将Google Drive API桥接至Swift
从以前删除的post :
我正努力让Google Drive API与Swift一起工作,并希望有人提出build议。 这是我到目前为止:我已经安装了Google Drive API,并在Objective-C中工作…
我试图在Swift中从Google复制这个例子 ,但import GTLDrive
在Xcode中返回一个错误:
没有这样的模块GTLDrive。
我无法从Swift类使用GTLServiceDrive
。 我应该使用哪种CocoaPod + 桥接头组合?
你需要3件事情:
(1)格式良好的Podfile
platform :ios, '8.0' target 'GoogleDrive' do pod 'Google-API-Client/Drive', '~> 1.0' end
(2)通过bridging headers
公开Google API
#import "GTMOAuth2ViewControllerTouch.h" #import "GTLDrive.h"
(3)Swift客户端类中不需要引用GTLDrive
override func viewDidLoad() { super.viewDidLoad() // ... let service:GTLServiceDrive = GTLServiceDrive() service.authorizer = GTMOAuth2ViewControllerTouch.authForGoogleFromKeychainForName("Drive API", clientID: "YOUR_CLIENT_ID_HERE", clientSecret: "YOUR_CLIENT_SECRET_HERE") // ... }
我刚刚在XCode 7.3中遇到了这个问题,并在桥接头文件中使用了以下内容:
#import <GoogleAPIClient/GTLDrive.h>
另外,如果您需要authentication部分:
#import <GTMOAuth2/GTMOAuth2ViewControllerTouch.h>
我从Swift中扔掉了Google API Objective C库,并创build了一个临时解决scheme: https : //github.com/metaprgmr/GoogleApiProxyForSwift 。 顺便说一下,我使用Google Drive作为一个guinnea猪,在那里你可以find实验接近其YouTube演示文稿的结尾。 一探究竟。