本文介绍了将Google Drive API连接到Swift的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
来自:
I我试图在Swift中重现,但导入GTLDrive
在Xcode中返回错误:
I am trying to reproduce this example from Google in Swift, but import GTLDrive
returns an error in Xcode:
我无法从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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!