Swift notes – Google Drive API Library integration for iOS

iOS integrate with Google Drive API

Recently I am planning to integrate the Google Drive function into my app.  Meanwhile, I have to include the Google API library into my project, however I feel the documentation and the tutorial I found was not perfect enough and also, I find out another clean method to integrate the API Library together with my current project.

It is quite easy while you search the keyword “Google Drive API iOS” by google, it will highly recommend you to go to this https://developers.google.com/drive/ios/quickstart

Well, you might notice it is quite tedious doing the following steps:

Step 1: Enable Drive API
Just follow the instructions to register and what we’ll need it later is Client ID and Client Secret.

Step 2: Download Google API
It is a must to download via SVN, as the data via manual download from github is not completed.

Step 3Create and configure an XCode project
This is the WORST part I feel it is very tricky and the documentation here is not very clear enough. Mostly people will have problem right here! Another thing I want to complain that the tutorial video is really WASTING YOUR TIME as the result come out was failed, and the speaker just opened another project to show you the result.

So I will suggest another solution at this part, which I feel clean and you don’t have to worry where to put your google-api folder and files.

From step 2, running the svn command:

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

you will have the folder google-api-objectivec-client-read-onlygoogle drive library folder

Go to google-api-objectivec-client-read-only/Source  Run the GTL.xcodeproj GTL xcode project

Build the project by running CMD+B
Build GTL project

Then open your own project, here is an advice to create a folder(group) in the project GTL group

Remember to link the path
Screen Shot 2015-04-09 at 2.10.10 PM

Go back to your GTL project, expand the folders under GTL Source/Common except a folder Mac

Here is the magic

Select from Common folder to the bottom, and drag to your project’s GTL folder.
drag file magic

Remember to tick copy items
copy items

Select your project, go to Build Phases -> Compile Sources and select all the files with prefix GTL and GTM
build phase compile sources

Press enter and there will have a dialog box prompt out, key in -fno-objc-arc and press enter again to add compiler flags.
flag no objective c arc

Use same method to create another group for Google Drive
Go back to your google-api-objectivec-client-read-only downloaded from SVN
Under google-api-objectivec-client-read-only/Source/Services/Drive/Generated

select all files except GTLDrive_Sources.m drag and copy to your project
copy google drive files

Well almost done! All You have to do now is adding the necessary framework into your project.

Security.framework
SystemConfiguration.framework
add framework

Ta-Da, the google drive library is set. You can build the project now if it doesn’t prompt any issue, then the library is successfully integrated!!

The rest, let’s run the example code to see whether it’s work!

For Swift project, remember to build your bridge header file, and import following files

#import "GTMOAuth2ViewControllerTouch.h"
#import "GTLDrive.h"

In order not to make my post longer, I have put the sample code in github, please download from here.

4 thoughts on “Swift notes – Google Drive API Library integration for iOS

  1. Thank you for this! I’m just getting started on the same road that you travelled, so this is very helpful. A big time saver!

Leave a comment