Skip to content

BuildingTheLibrary

Thomas Van Lenten edited this page Apr 4, 2019 · 13 revisions

Adding the Google APIs Objective-C Client Library for REST to a Project

The Google APIs Objective-C Client Library includes the core library classes, along with service-specific classes, such as for Google Calendar and Google Drive.

The core classes are provided as a built framework, suitable for inclusion in an application bundle's Frameworks folder.

Alternatively, all of the library's sources may also be compiled directly into a Mac or an iOS application.

Service-specific classes are provided in a separate folder for each service API. They are not compiled into the library or framework with the core classes, so the needed service class files should should be dragged into the application project.

Use one of the following three approaches to add the library to your project.

CocoaPods

If you are building from CocoaPods, just use the pod provided, GoogleAPIClientForREST.

The Core subspec includes the common parts of the library. There is also a subspec for each service API provided, such as Calendar and Drive. Your project can just depend on one or more service subspecs, and the core library files will be built as well.

See the podspec file for the subspec names.

The GoogleAPIClientForREST podspec does not include a dependency on any authentication support, if you plan on using an api that also needs authentication, you'll either want to use GTMAppAuth by depending on GTMAppAuth also, or you can use something else like the Google Sign-In SDK; see their site for full information this.

NOTE: The Oauth2 subspec in the pod is NOT needed for authentication, that is for talking to that service directly. You just need something like GTMAppAuth.

Linking to the Framework

To add the framework to an Xcode project, drag GTLR.framework to the project's Linked Frameworks source group, then add the GTLR framework from the Linked Frameworks and Libraries and Embedded Binaries phases inside of the application target.

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

For both debug and release builds of your application, add this define to your project file:

Preprocessor Macros: GTLR_BUILT_AS_FRAMEWORK=1

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

#import "GTLRCalendar.h"

To facilitate debugging, you may choose to include the GTLR.xcodeproj project file either in an Xcode workspace for your application or directly in your application project as a cross-project reference. The example applications show how to include a reference to the GTLR framework project file in an Xcode project.

Tip: if Xcode's debugger is ignoring breakpoints set in the framework, turn off the "Load symbols lazily" option in Xcode's Debugging preferences.

For authentication support, pick one of the options and also add that to your project.

Compiling the Source Files Directly into an Application

Rather than link to the GTLR framework, you can compile the GTLR library sources directly into your own project.

To do this, find the library's GTLRCommon_Sources.m in Sources/ and drag the file into your project's window.

Then add the library's source folders to the Header Search Paths entry of your project's build settings: Source, Source/Objects, Source/Utilities, Deps/gtm-session-fetcher/Source.

Also add to your project the sources files for the services needed by your application, such as Calendar or Books. From the generated files folder, drag into your project the service's sources (.h and .m files).

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

#import "GTLCalendar.h"

For just the Debug configuration of your project, add this compiler definition to ensure that the library's debug-only code is included:

Preprocessor Macros: DEBUG=1

Or, if the Preprocessor Macros setting is not available in your target's build options, set the equivalent user-defined setting:

GCC_PREPROCESSOR_DEFINITIONS =-DDEBUG=1

If you don't already have them, you also need to include the GTMSessionFetcher sources, see their directions on adding that.

For authentication support, pick one of the options and also add that to your project.

Using a Swift Bridging Header

When Xcode compiles a bridging header, it silently drops all properties for types that were only forward declared. This commonly comes up for the authorizer property on GTLRService. To have these properties work via the bridging header, you need to ensure you #import the gtm-session-fetcher headers also, i.e. -

#import <GTMSessionFetcher/GTMSessionFetcher.h>		
#import <GTMSessionFetcher/GTMSessionFetcherService.h>

NOTE: The exact import syntax will depend on which method you used to integrate the library. CocoaPods will likely be the above, other methods might be different.

You can’t perform that action at this time.