Monday 3 September 2012

Google Objective-C Client Api Xcode Integration for iOS Tutorial

Hi there,

I have been working on the google's new client library for objective-C. I find it quite difficult to integrate it first in my project. But somehow I successfully integrated and thought if I make a tutorial on how to integrate someone out there might save time. :)

So here is it.


Written by Google, this library is a flexible and efficient Objective-C framework for accessing JSON APIs for iOS applications. The library is compatible with applications built for iOS 3 or above. More information on library is here.

Step 1

First thing to do is check out the GTL library project from here.


Step 2

Now go to the directory where you have checked out project and from source folder open GTL.xcodeproj in Xcode.

Now select GTLTouchStaticLib as your active scheme and build the project. (command+B)



Step 3

After you have compiled and build, goto Organiser->Projects->GTL and click on the little arrow for Derived  Data. 



You will find libGTLTouchStaticLib.a file and Headers folder in derived data's project folder->Build->Products->Debug-iphoneos



The static library file should be dragged into your application(in which you want to integrate google client library) project's Build Phases "Link Binary with Libraries" list.


Also do not forget to add SystemConfiguration and Security framework in your project.



Step 4

Next, add the ObjC link options to the application target's build settings, along with the all_load flag

Other Linker Flags: -ObjC -all_load





Step 5

Drag the folder with the class files for the services from GTL project folder needed by your application, such as Tasks or Books, directly into your project.

Application classes using the library should include the header for each specific service, such as

#import "GTLTasks.h"



Step 6


Write the code for your application. Happy Coding :)

15 comments:

  1. Thanks for the post. I'm too am struggling to get the api integrated with my API project. After reading this tutorial I fell like I'm ALMOST there. I would love it you could post a quick video of integrating it. I seem to be missing a step somewhere - and watching it would be awesome.

    ReplyDelete
    Replies
    1. Tell me the step, where are you having trouble?

      Delete
  2. The tutorial is very good, but you forgot to mention two things:
    a. You have to put the headers folder (from the derived data) into your project as well
    b. When you copy in your services folder (e.g. YouTube), you have to put it iinto your project AND then delete the Youtube_Sources.m, or you'll get a ton of errors

    ReplyDelete
  3. Hi, thanks for the tutorial, this is awesome so far.

    Can you elaborate ob Step 5?
    Drag the folder with the class files for the services from GTL project folder needed by your application, such as Tasks or Books, directly into your project.

    Like where are class files, say for Tasks or Books? I'm trying to integrate Youtube API, where would I find their source files?

    Thank you.

    ReplyDelete
  4. David,

    Checkout library source from here and here you will find header files for each service e.g youtube, books or analytics.

    https://code.google.com/p/google-api-objectivec-client/source/checkout

    ReplyDelete
  5. hi .... i have copleted the above process......but i want to code for upload video as well.
    Thanx

    ReplyDelete
  6. Thank you very much. This is by far the most comprehensive tutorial for YouTube API integration. It is much better than the google wiki which is too confusing. I finally get the API working after reading this article.

    David,

    I think Step 5 is to drag and copy the files in the header folder in the same directory of the libGTLTouchStaticLib.a file to the project. I did that and built successfully.

    ReplyDelete
  7. Thanks Jawad Waheed,

    With images you makes the tip easier to follow. Just in case someone stuck with error. I will simplify something.

    Step 1, 2 as follow

    Step 3.
    With the libGTLTouchStaticLib.a & Header folder you find out in derived data's project folder->Build->Products->Debug-iphoneos

    - Drag libGTLTouchStaticLib.a file into Build Phases "Link Binary with Libraries"
    - Drag Header folder into project
    Also remember to add Security.framework & SystemConfiguration.framework

    Step 4: As follow

    Step 5: Open Finder, go to GTL project folder
    go to Services folder, you will see a list of Service, choose some service folders you need and drag directly into your application

    Step6: Go to your service folder in xcode application > Generated > find the one file with suffix _Sources.m , and delete it

    ReplyDelete
  8. thanks so much! your article saved a lot of scratching my head!

    ReplyDelete
  9. Very useful tutorial. Thank you for sharing.

    ReplyDelete
  10. THANK YOU, i spent half day on this.. sorry but STUPID google, could make it easier

    ReplyDelete
  11. This comment has been removed by the author.

    ReplyDelete
  12. Thx Jawad for the post and Binh Lee for further clarifying the matter.

    I'd just like to say that, despite google documentation saying for each service you need "either the individual class .m files for the service or the service's _Sources.m file, but not both", I tried using only the _Sources.m and it wouldn't work. I did as Binh Lee stated and copied the whole generated .h and .m files, deleted the _Sources.m and it worked.
    Best

    ReplyDelete
  13. Glad I found this post, it also helped me a lot! Many Thanks.

    I was having link errors, complaining about the arm64 architecture for some symbols.
    "Undefined symbols for architecture arm64"
    I only added the youtube service.

    I removed arm64 from build settings and builds fine... but now I'm concerned about not building for the arm64 ...

    Has anyone came across this??
    Regards

    ReplyDelete