Adding Google Objective-C API 'GTL' to iPhone project

后端 未结 5 594
隐瞒了意图╮
隐瞒了意图╮ 2020-12-24 03:50

How to I add the Google Drive API to my iPhone project to I can use it?

So far, I have dragged the GTL project into my current app project (so that it is nested unde

相关标签:
5条回答
  • 2020-12-24 04:16

    Not only doing the above, but go under "[Project Name] Targets->Build Phases> Compile Sources" and click the + button. Then add all the .m files, for some reason most of the aren't automatically.

    I also had to delete (the reference) to "GTLDrive_Souces.m" from the Drive folder, but I don't understand why i had to do that part.

    0 讨论(0)
  • 2020-12-24 04:18

    this is does not really solve the problem of installing Google API's but in this repo I accessed Google Forms from an iOS app without using Google's API. https://github.com/goktugyil/QorumLogs

    So you may skip the installing API part in some projects

    Here is the tutorial of how to set it up: https://github.com/goktugyil/QorumLogs/blob/master/Log%20To%20GoogleDocs.md

    Heres the code to do it:

    private static var googleFormLink: String!
    private static var googleFormAppVersionField: String!
    private static var googleFormUserInfoField: String!
    private static var googleFormMethodInfoField: String!
    private static var googleFormErrorTextField: String!
    
    /// Setup Google Form links
    static func setupOnlineLogs(#formLink: String, versionField: String, userInfoField: String, methodInfoField: String, textField: String) {
        googleFormLink = formLink
        googleFormAppVersionField = versionField
        googleFormUserInfoField = userInfoField
        googleFormMethodInfoField = methodInfoField
        googleFormErrorTextField = textField
    }
    
    private static func sendError(#text: String) {
        var url = NSURL(string: googleFormLink)
        var postData = googleFormAppVersionField + "=" + text
        postData += "&" + googleFormUserInfoField + "=" + "anothertext"                
        postData += "&" + googleFormMethodInfoField + "=" + "anothertext" 
        postData += "&" + googleFormErrorTextField + "=" + "anothertext" 
    
        var request = NSMutableURLRequest(URL: url!)
        request.HTTPMethod = "POST"
        request.setValue("application/x-www-form-urlencoded; charset=utf-8", forHTTPHeaderField: "Content-Type")
        request.HTTPBody = postData.dataUsingEncoding(NSUTF8StringEncoding)
        var connection = NSURLConnection(request: request, delegate: nil, startImmediately: true)
    }
    
    0 讨论(0)
  • 2020-12-24 04:26

    I struggled with this error message as well. This is how I solved it:

    Make sure you have added the folder for the service that you are using under GTLSource/Common/ (e.g., add the Drive folder for GoogleDrive).

    Under GTL.xcodeproj (that you have already added to your workspace) find the GTLSource folder and drag it to your main project (Golf in your case). Done!

    Now you can remove references to the GTL.xcodeproj that you have added to the workspace.

    With this approach, you don't even need to add the libraries (so remove them from the list of linked libraries if you have added them).

    The Google API documentation is nothing like Apple's documentation (it's not good).

    I should also mention that I'm building an app for iOS and not MacOSX, but this should work for OSX as well.

    enter image description here

    0 讨论(0)
  • 2020-12-24 04:31

    I struggled with this exact issue for most of the day today, and I found it extremely frustrating. I have finally figured it all out so here is a straightforward step by step guide on how to add the Google API to an iOS7 project using XCode5, using ARC, without having to create Workspaces or any of that.

    The answer provided by RawMean works well, but it gave me issues with ARC. I also didn't like the fact that you had to add project, create a workspace and then delete the project. So my solution will deal with both these issues.

    1. Check out the code. To do this, you can just run svn checkout http://google-api-objectivec-client.googlecode.com/svn/trunk/ google-api-objectivec-client-read-only from your terminal. I will refer to this code as "Google's code".
    2. Go to your project's Build Phases. Expand "Link Binary With Libraries" and add Security.framework and SystemConfiguration.framework. These two are required by Google's code.
    3. Go to your project's Build Settings. Using the search box there, look for Other Linker Flags (make sure "All" is selected to the left of the search box). Add -ObjC -all_load.
    4. Now search for User headers search path and add the full path to Goggle's /Source directory. Make sure you select recursive.
    5. Using Finder, go to Google's /Source/OAuth2/Touch directory. Drag and drop GTMOAuth2ViewTouch.xib into your project.
    6. Go back to Finder and go to Google's /Source directory. Drag and drop GTLCommon_Sources.m and GTLCommon_Networking.m into your project.
    7. Now, you need to import the files for the services you want to use. In my case, I need to use Google Drive, so I'll add those. In finder, go to Google's /Source/Services/Drive/Generated directory. Drag and drop GTLDrive.h and GTLDrive_Sources.m into your project. If you want to use other services, go to their directory and import the appropriate .h and .m file.
    8. For some reason, Google's code doesn't use ARC, so if you try to build right now, you will get ARC compile errors. So we need to disable ARC for Google's code only. To do this, go back to your project's Build Phases, but this time expand "Compile Sources". Make sure that GTLCommon_Sources.m and GTLCommon_Networking.m are there. Select them, press enter and type in -fno-objc-arc. This will disable ARC for both of them. Make sure you don't add this option for any other file (unless you know what you're doing).
    9. You are done! Now, whenever you want to use Google's API, just import GTMOAuth2ViewControllerTouch.h and your service header. In my case, since I'm using Google Drive, I will also import GTLDrive.h.

    I hope that helps and saves some people from pulling all their hair out.

    0 讨论(0)
  • 2020-12-24 04:37

    Better to use Pod

    1. How to install CocoaPods and setup with your Xcode project for reference : [http://blogs.triffort.com/?p=309][1]
    2. Open the pod file and add

      pod 'Google-API-Client/Drive', '~> 1.0' save pod file and call pod install in terminal. Note:pod file you must give link_with 'Your_project_name', 'Your_project_nameTests' after this line only add your library

    0 讨论(0)
提交回复
热议问题