LRGoogle Plus Client was created to simplify the integration of Google Plus framework into an iOS App.
Since the Google documentation is pretty extensive, but not always that clear - I went onwards with creating a simpler solution - a singleton class that does anything from logging in , one line sharing and properly notifying you on various events.
I find this solution much easier to implement and maintain as it also removes a lot of the overhead when copying this solution from project to project.
The less code you duplicate and write - the less bugs you will have.
This version has currently been tested against Google Plus SDK 1.5.1 and 1.7.0
-
Copy LRGooglePlusClient into your project
-
Either download (https://developers.google.com/+/mobile/ios/) drag the Google plus library into your project or LRGooglePlusClient is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod "LRGooglePlusClient"
-
Follow the instructions to create a Google Plus App (Steps 1-3): https://developers.google.com/+/mobile/ios/getting-started
-
Write down the Client ID of your specific app from: https://code.google.com/apis/console Go to the old version -> API Access
-
In the App Delegate add the following:
-
Import LRGooglePlusClient Header:
#import "LRGooglePlusClient.h"
-
Start up shared instance with the client ID:
[[LRGooglePlusClient sharedInstance] setClientID:<client id>];
-
Add the following method to handle URL scheme and SSO:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { return [[LRGooglePlusClient sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation]; }
-
If you have more then one URL scheme handling component you can instead use the following snippet to ease integration:
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation { if ([[LRGooglePlusClient sharedInstance] application:application openURL:url sourceApplication:sourceApplication annotation:annotation] == NO) { // Add you URL handling code } else { return YES; } }
-
And ... That's it - you finished your integration and are ready to start sharing.
Before going into the sharing methods - you might note there are sign in , sign out and disconnect methods. While those methods exist to simplify the usage and give you the opportunity to present relevant UI - if you try to share without logging in - it will simply save the share data until a successful login has happened.
Sign in with Google plus method.
Sign out current user from Google Plus.
Differs from sign out by also removing the application authorization and completely disconnecting the user from the Google App.
Share a URL and text. Note - the description , Title and thumbnail URL are taken from the URL tags themselves.
Share with Title , Description , Thumbnail URL , URL and Prefill text. Do note - the URL information overrides the rest of the fields.
This share method is basically here mainly to be used after a sign in. In case a user tried sharing and was not signed in - The LLGooglePlusClient serializes the sharing info into a dictionary and uses it after a successful sign in in order to restore the sharing request.
To simplify understanding the current state of actions and to ease adding various analytics around actions - I created a few notifications to better understand the flow and lifecycle of the Google Plus Client:
This notification is called when the Google Plus share is successfully sent.
This notification is sent when Google Plus did Login.
This notification is sent when Google Plus did Logout.
This notification is sent when Google Plus didn't manage to Login.
Liviu Romascanu, livius16@gmail.com
LRGooglePlusClient is available under the MIT license. See the LICENSE file for more info.