Bridge Google Drive API to Swift

前端 未结 3 995
深忆病人
深忆病人 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:26

    I threw away Google API Objective C library from Swift altogether and created an interim solution: https://github.com/metaprgmr/GoogleApiProxyForSwift. Incidentally, I used Google Drive as a guinnea pig, where you can find experiments at close to the end of its YouTube presentation. Check it out.

    0 讨论(0)
  • 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")
    
        // ...
    }
    
    0 讨论(0)
  • 2020-12-07 03:45

    I just ran into that now in XCode 7.3, and fixed it with the following in the bridging header:

    #import <GoogleAPIClient/GTLDrive.h>
    

    Also, if you need the authentication portion:

    #import <GTMOAuth2/GTMOAuth2ViewControllerTouch.h>
    
    0 讨论(0)
提交回复
热议问题