【问题标题】:Bridge Google Drive API to Swift将 Google Drive API 桥接到 Swift
【发布时间】:2015-07-26 20:16:56
【问题描述】:

来自previously removed post

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

我试图在 Swift 中重现 this example from Google,但 import GTLDrive 在 Xcode 中返回错误:

没有这样的模块'GTLDrive。

我无法在 Swift 类中使用 GTLServiceDrive。 我应该使用 CocoaPod + 桥接头的哪种组合?

【问题讨论】:

  • 这是一个 5 小时前从其他用户发布的重要问题,在回答之前已被删除。解决方案如下。

标签: ios swift cocoapods


【解决方案1】:

你需要三样东西:

(1) 格式良好的 Podfile

platform :ios, '8.0'

target 'GoogleDrive' do
pod 'Google-API-Client/Drive', '~> 1.0'
end

(2) 通过bridging headers公开Goog​​le 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")

    // ...
}

【讨论】:

【解决方案2】:

我现在在 XCode 7.3 中遇到了这个问题,并在桥接头中使用以下内容对其进行了修复:

#import <GoogleAPIClient/GTLDrive.h>

另外,如果您需要身份验证部分:

#import <GTMOAuth2/GTMOAuth2ViewControllerTouch.h>

【讨论】:

    【解决方案3】:

    我完全放弃了 Swift 中的 Google API Objective C 库,并创建了一个临时解决方案:https://github.com/metaprgmr/GoogleApiProxyForSwift。顺便说一句,我将 Google Drive 用作豚鼠,您可以在其 YouTube 演示文稿接近尾声时找到实验。看看吧。

    【讨论】:

    • 不错。出于纯粹的好奇,我概述的解决方案不适合您吗?
    猜你喜欢
    • 1970-01-01
    • 2016-09-30
    • 2020-03-10
    • 1970-01-01
    • 1970-01-01
    • 2020-08-11
    • 1970-01-01
    • 2020-11-03
    • 1970-01-01
    相关资源
    最近更新 更多