Jun
8

How To Use Google APIs with iPhone SDK

Adding Google API support to your iPhone App could not be any easier. Google provides Objective-C APIs for:

Step 1

The first step, is to head on over to the Google Code website for the Objective-C Client, download and extract the zip file source code. Alternatively, you can get the latest and greatest version via Subversion using:

 svn checkout http://gdata-objectivec-client.googlecode.com/svn/trunk/ gdata-objectivec-client-read-only

If you downloaded the zip file from the website, you’ll have version 1.7.0, and if you used the svn code you’ll have a -read-only folder.

Step 2

Open up the GData XCode Project from your downloaded folder as well as your iPhone App XCode project.

extracted

Step 3

Drag over the GData Sources Folder from the GData project to your iPhone App project and add it as reference [don't check the box for Copy items into destination group's folder (if needed).] You do not need to copy over all the files into your project. You can, but it’s not required.

to_drag

copy_reference

This will add a ton of files to your project. You may delete the APIs you are not planning on using, but make sure that the files GDataXMLNode.m and GDataXMLNode.h in the Common/Optional/XMLSupport group are not removed from your project as they are required for iPhone builds.

files

Step 4

Open up the build settings for your iPhone App project. Located and set the following settings.

  • Header Search Paths: /usr/include/libxml2
  • Other Linker Flags: -lxml2

For the Debug build configuration only, add the Other C Flags setting so that the library’s debug-only code is included:

  • Other C Flags: -DDEBUG=1

build

Step 5 (Optional for iPhone 3.0 Beta SDK)

If you downloaded the zip file version (1.7.0) of the API, you will also run into this error message when you attempt to first build your iPhone App project:

...Source/Networking/GDataHTTPFetcherLogging.m:224: error: 'NSTask' undeclared (first use in
...Source/Networking/GDataHTTPFetcherLogging.m:224: error: 'task' undeclared (first use in this
function)

Error Message

Apple has removed the NSTask from the Foundations Framework in the iPhone 3.0 SDK. In order to fix this, simply open up the GDataDefines.h file, find the developer section and add:

#define  GDATA_SKIP_LOG_XMLFORMAT 1

gdefine

Note: This fix is only needed if you downloaded version 1.7.0 of the GData Objective-C API and are using iPhone 3.0 Beta SDK. If you downloaded the latest Subversion read-only trunk of the code or are using iPhone 2.2.1 SDK, you do not need to do this.

Step 6

At this point, your iPhone XCode project should build successfully and you can begin using the Google APIs by simply importing the appropriate header files. ie.

#import "GDataAnalytics.h"

Step 7 (Optional if downloaded GData version 1.7.0 Zip file)

If you downloaded the zip file version (1.7.0) of the API, you will be missing the Analytics API. That has not yet been zipped up for the download. You may want to download those separately.

Additional Resources:

Share the Love:
  • Digg
  • del.icio.us
  • Facebook
  • StumbleUpon
  • Design Float
  • Reddit
  • DZone
  • FriendFeed
  • Twitter
  • email
  • Print

Related Posts

  • Thank you for this post. My compile ran error free first run (Xcode 3.1.4/IPhone SDK 3.1.2)

    The only differences:

    For step 4, I used "$SDKROOT/usr/include/libxml2"

    I used SVN to get the latest sources and then manually placed them into a GoogleAPI folder matching the "Groups" that are in your GData project. Then I added my GoogleAPI folder to the project.
  • iphoneapp
    Thanks John. The other thing i am confused a bit is do i need to drag "GData Source" folder or "GData Project" file. According to the article posted on the google code website( http://code.google.com/p/gdata-objectivec-clien...) " To build with the static library, drag the GData project file itself into an iPhone project to make a cross-project reference, and add the GDataTouchStaticLib target as a dependency for building the app. " It is very confusing to me, i am trying to figure out how to create a static library and dependencies. Do i really need to do this.
    I am also getting some errors regarding XML file eg. tree.h not found.
    Any help is appreciated.
    Thanks
  • You can drag the Project file itself in the new version (1.8) of the GData code. At the time of writing, I believe I was using version 1.7 of the code. It has since been updated. I'll be updating the post accordingly.

    Yes, you do need to do all of this. Otherwise, you won't be able to fully access all the data. It sounds like you missed an #import statement somewhere. If it's not too confidential, you may want to either post what you're trying to link to, or try contacting Greg at the GData Objective-C Google Group [ http://groups.google.com/group/gdata-objectivec... ]. He may be able to help you further.
  • iphoneapp
    Thanks John, I will try it again.
  • where Do I change the build settings? I'm lost on Step 4
  • Open up the Inspector for your App or Target and chose the Build Settings tab. If that's not enough explanation, Apple has some more here:
    http://developer.apple.com/Tools/xcode/xcodebui...
    http://developer.apple.com/tools/xcode/xcodepro...

    Otherwise, If that's too over the top, I can post up a few more screenshots and explanations on how to get to that section. Just let me know if you need me to do that.
  • iphoneapp
    Wonderful Info John. I am wondering which is the best iphone template to use for developing iphone app with Google API. Thanks a lot.
  • For using the Google APIs it doesn't really matter which one you pick. If you're doing the Tab Bar functionality, that's a good one to chose. If you're going to do everything in code, I'd chose Window or View Based. Otherwise, Tab Bar and Navigation are just as good. They all work well with the Google APIs.

    Three20 on the other hand, I'd go with Window Based or View Based for sure.
blog comments powered by Disqus