将Google Drive API连接到Swift

Swi*_*ect 4 ios cocoapods swift

之前删除的帖子:

我正在努力让Google Drive API与Swift一起使用,并希望有人提出建议.这是我到目前为止的位置:我安装了Google Drive API并在Objective-C中工作...

我试图在Swift中从Google重现此示例,但import GTLDrive在Xcode中返回错误:

没有这样的模块'GTLDrive.

我无法使用GTLServiceDriveSwift类.我应该使用CocoaPod + 桥接头的哪个组合?

Swi*_*ect 6

你需要3件事:

(1)格式良好的Podfile

platform :ios, '8.0'

target 'GoogleDrive' do
pod 'Google-API-Client/Drive', '~> 1.0'
end
Run Code Online (Sandbox Code Playgroud)

(2)通过以下方式公开Goog​​le API bridging headers

#import "GTMOAuth2ViewControllerTouch.h"
#import "GTLDrive.h"
Run Code Online (Sandbox Code Playgroud)

(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")

    // ...
}
Run Code Online (Sandbox Code Playgroud)