Adding Google API support to your iPhone App could not be any easier. Google provides Objective-C APIs for:
- Google Base
- Analytics - (Only available via SVN Trunk or manual download)
- Book Search
- Code Search
- Documents List
- Picasa Web Albums
- Webmaster Tools
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.
Open up the GData XCode Project from your downloaded folder as well as your iPhone App XCode project.
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.
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.
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
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)
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
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.
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. i.e.
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.