将Google Drive API连接到Swift [英] Bridge Google Drive API to Swift
问题描述
来自之前删除的帖子:
我正在努力让Google Drive API与Swift合作,并希望有人提出建议。以下是我目前所处的位置:我安装了Google Drive API,并在Objective-C中工作...
I am struggling to get the Google Drive API to work with Swift, and hoping someone has a suggestion. Here is where I am at so far: I have the Google Drive API installed and working in an Objective-C ...
I我试图在Swift中重现这个来自Google的示例,但导入GTLDrive
在Xcode中返回错误:
I am trying to reproduce this example from Google in Swift, but import GTLDrive
returns an error in Xcode:
没有这样的模块'GTLDrive。
No such module 'GTLDrive.
我无法从Swift类中使用 GTLServiceDrive
。
我应该使用CocoaPod + 桥接头的哪个组合?
I am unable to use GTLServiceDrive
from the Swift classes.
Which combination of CocoaPod + bridging header should I use?
推荐答案
你需要3个事情:
(1)格式良好的Podfile
platform :ios, '8.0'
target 'GoogleDrive' do
pod 'Google-API-Client/Drive', '~> 1.0'
end
(2)通过<$ c公开Google API $ c>桥接标题
(2) Expose Google API through the bridging headers
#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")
// ...
}
这篇关于将Google Drive API连接到Swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!