Bridge Google Drive API to Swift

前端 未结 3 997
深忆病人
深忆病人 2020-12-07 02:53

From a previously removed post:

I am struggling to get the Google Drive API to work with Swift, and hoping someone has a suggestion. Here is where I a

3条回答
  •  旧巷少年郎
    2020-12-07 03:43

    You need 3 things:

    (1) Well formed Podfile

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

    (2) Expose Google API through the bridging headers

    #import "GTMOAuth2ViewControllerTouch.h"
    #import "GTLDrive.h"
    

    (3) No reference GTLDrive required in the Swift client class

    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")
    
        // ...
    }
    

提交回复
热议问题