2012-08-25 10:38:29 +00:00
|
|
|
//
|
2013-01-31 21:22:37 +00:00
|
|
|
// GPPShare.h
|
2012-08-25 10:38:29 +00:00
|
|
|
// Google+ iOS SDK
|
|
|
|
//
|
|
|
|
// Copyright 2012 Google Inc.
|
|
|
|
//
|
2013-04-27 21:14:05 +00:00
|
|
|
// Use of this SDK is subject to the Google+ Platform Terms of Service:
|
2012-08-25 10:38:29 +00:00
|
|
|
// https://developers.google.com/+/terms
|
|
|
|
//
|
|
|
|
|
|
|
|
// To allow a user to share with Google+, please follow these steps:
|
|
|
|
//
|
2013-04-27 21:14:05 +00:00
|
|
|
// 0. Create a project on Google API console,
|
2012-08-25 10:38:29 +00:00
|
|
|
// https://code.google.com/apis/console . Under "API Access", create a
|
|
|
|
// client ID as "Installed application" with the type "iOS", and
|
2013-04-27 21:14:05 +00:00
|
|
|
// register the bundle ID of your app.
|
2012-08-25 10:38:29 +00:00
|
|
|
//
|
2013-04-27 21:14:05 +00:00
|
|
|
// 1. Initialize the |GPPSignIn| instance with your registered client ID,
|
|
|
|
// and get the |GPPShare| instance.
|
2012-08-25 10:38:29 +00:00
|
|
|
//
|
2013-04-27 21:14:05 +00:00
|
|
|
// [[GPPSignIn shareInstance] setClientID:myClientID];
|
|
|
|
// GPPShare *gppShare = [GPPShare sharedInstance];
|
2012-08-25 10:38:29 +00:00
|
|
|
//
|
2013-04-27 21:14:05 +00:00
|
|
|
// 2. In the code where the share dialog will be opened,
|
2012-08-25 10:38:29 +00:00
|
|
|
//
|
2013-01-31 21:22:37 +00:00
|
|
|
// [[gppShare shareDialog] open];
|
2012-08-25 10:38:29 +00:00
|
|
|
//
|
2013-04-27 21:14:05 +00:00
|
|
|
// you can optionally call any of the |GPPShareBuilder| methods before
|
|
|
|
// calling |open|, for example, if there is a particular URL resource to be
|
|
|
|
// shared, or if you want to set text to prefill user comment in the share
|
|
|
|
// dialog, such as:
|
2012-08-25 10:38:29 +00:00
|
|
|
//
|
|
|
|
// NSURL *urlToShare = [NSURL URLWithString:@"http://www.google.com/"];
|
|
|
|
// NSString *prefillText = @"You probably already know this site...";
|
2013-01-31 21:22:37 +00:00
|
|
|
// [[[[gppShare shareDialog] setURLToShare:urlToShare]
|
2012-08-25 10:38:29 +00:00
|
|
|
// setPrefillText:prefillText] open];
|
|
|
|
//
|
2013-04-27 21:14:05 +00:00
|
|
|
// 3. In the '<YourApp>-info.plist' settings for your app, add a URL type to be
|
|
|
|
// handled by your app. Make the URL scheme the same as your app bundle ID.
|
2012-08-25 10:38:29 +00:00
|
|
|
//
|
2013-04-27 21:14:05 +00:00
|
|
|
// 4. In your application delegate, implement:
|
2012-08-25 10:38:29 +00:00
|
|
|
// - (BOOL)application:(NSString*)application
|
|
|
|
// openURL:(NSURL *)url
|
|
|
|
// sourceApplication:(NSString*)sourceApplication
|
|
|
|
// annotation:(id)annotation {
|
2013-01-31 21:22:37 +00:00
|
|
|
// if ([gppShare handleURL:url
|
|
|
|
// sourceApplication:sourceApplication
|
|
|
|
// annotation:annotation]) {
|
2012-08-25 10:38:29 +00:00
|
|
|
// return YES;
|
|
|
|
// }
|
|
|
|
// // Other handling code here...
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// 5. Optionally, if you want to be notified of the result of the share action,
|
2013-04-27 21:14:05 +00:00
|
|
|
// have a delegate class implement |GPPShareDelegate|, for example:
|
2012-08-25 10:38:29 +00:00
|
|
|
//
|
2013-01-31 21:22:37 +00:00
|
|
|
// @interface MyDelegateClass : NSObject<GPPShareDelegate>;
|
2012-08-25 10:38:29 +00:00
|
|
|
//
|
|
|
|
// - (void)finishedSharing:(BOOL)shared {
|
|
|
|
// // The share action was successful if |shared| is YES.
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
// MyDelegateClass *myDelegate = [[MyDelegateClass alloc] init];
|
2013-01-31 21:22:37 +00:00
|
|
|
// gppShare.delegate = myDelegate;
|
2012-08-25 10:38:29 +00:00
|
|
|
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
|
2013-04-27 21:14:05 +00:00
|
|
|
@class GPPSignIn;
|
|
|
|
|
|
|
|
// The protocol to receive the result of the share action.
|
2013-01-31 21:22:37 +00:00
|
|
|
@protocol GPPShareDelegate
|
2012-08-25 10:38:29 +00:00
|
|
|
|
|
|
|
// Reports the status of the share action, |shared| is |YES| if user has
|
2013-04-27 21:14:05 +00:00
|
|
|
// successfully shared her post, |NO| otherwise, such as if the user canceled
|
|
|
|
// the post.
|
2012-08-25 10:38:29 +00:00
|
|
|
- (void)finishedSharing:(BOOL)shared;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
// The builder protocol to open the share dialog.
|
2013-04-27 21:14:05 +00:00
|
|
|
// For more information on sharing, see
|
|
|
|
// http://developers.google.com/+/mobile/ios/share .
|
2013-01-31 21:22:37 +00:00
|
|
|
@protocol GPPShareBuilder<NSCopying>
|
2012-08-25 10:38:29 +00:00
|
|
|
|
|
|
|
// Sets the URL resource to be shared.
|
2013-01-31 21:22:37 +00:00
|
|
|
- (id<GPPShareBuilder>)setURLToShare:(NSURL *)urlToShare;
|
2012-08-25 10:38:29 +00:00
|
|
|
|
2013-04-27 21:14:05 +00:00
|
|
|
// Sets the text to prefill user's comment in the share dialog.
|
2013-01-31 21:22:37 +00:00
|
|
|
- (id<GPPShareBuilder>)setPrefillText:(NSString *)prefillText;
|
2012-08-25 10:38:29 +00:00
|
|
|
|
2013-01-31 21:22:37 +00:00
|
|
|
// Sets the title, description, and thumbnail URL of the shared content preview
|
|
|
|
// in the share dialog. Only set these fields if you are sharing with a content
|
2013-04-27 21:14:05 +00:00
|
|
|
// deep link and don't have a URL resource. |title| is required.
|
2013-01-31 21:22:37 +00:00
|
|
|
- (id<GPPShareBuilder>)setTitle:(NSString *)title
|
|
|
|
description:(NSString *)description
|
|
|
|
thumbnailURL:(NSURL *)thumbnailURL;
|
|
|
|
|
|
|
|
// Sets the content deep-link ID that takes the user straight to your shared
|
|
|
|
// content. Only set this field if you want the content deep-linking feature.
|
|
|
|
// The content deep-link ID can either be a fully qualified URI, or URI path,
|
2013-04-27 21:14:05 +00:00
|
|
|
// which can be up to 512 characters in length.
|
2013-01-31 21:22:37 +00:00
|
|
|
- (id<GPPShareBuilder>)setContentDeepLinkID:(NSString *)contentDeepLinkID;
|
|
|
|
|
2013-04-27 21:14:05 +00:00
|
|
|
// Sets the call-to-action button of the shared content preview.
|
|
|
|
// The call-to-action button consists of a label, URL, and deep-link ID.
|
|
|
|
// The |label| is a string key defined under "data-calltoactionlabel" on
|
|
|
|
// http://developers.google.com/+/web/share/interactive#button_attr_calltoactionlabel
|
|
|
|
// that maps to the actual button text.
|
|
|
|
// You must set either the |url| or |deepLinkID|, or both.
|
|
|
|
// The |url| is where the user is taken to after tapping on the button.
|
|
|
|
// The |deepLinkID| is the call-to-action deep-link ID that takes the user
|
|
|
|
// straight to a specific action in your app. It can either be a fully qualified
|
|
|
|
// URI, or URI path, which can be up to 512 characters in length.
|
|
|
|
// Note: In order to set the call-to-action button:
|
|
|
|
// 1. User must have been authenticated with scopes including
|
|
|
|
// "https://www.googleapis.com/auth/plus.login".
|
|
|
|
// 2. Either |setURLToShare:| or |setTitle:description:thumbnailURL:| must also
|
|
|
|
// be called.
|
|
|
|
- (id<GPPShareBuilder>)setCallToActionButtonWithLabel:(NSString *)label
|
|
|
|
URL:(NSURL *)url
|
|
|
|
deepLinkID:(NSString *)deepLinkID;
|
|
|
|
|
2013-01-31 21:22:37 +00:00
|
|
|
// Opens the share dialog. Returns |NO| if there was an error, |YES| otherwise.
|
|
|
|
- (BOOL)open;
|
2012-08-25 10:38:29 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
// The primary class for the share action on Google+.
|
2013-04-27 21:14:05 +00:00
|
|
|
// For more information on sharing, see
|
|
|
|
// http://developers.google.com/+/mobile/ios/share .
|
2013-01-31 21:22:37 +00:00
|
|
|
@interface GPPShare : NSObject
|
2012-08-25 10:38:29 +00:00
|
|
|
|
|
|
|
// The object to be notified when the share action has finished.
|
2013-01-31 21:22:37 +00:00
|
|
|
@property (nonatomic, assign) id<GPPShareDelegate> delegate;
|
2012-08-25 10:38:29 +00:00
|
|
|
|
2013-04-27 21:14:05 +00:00
|
|
|
// Returns a shared |GPPShare| instance.
|
|
|
|
// |[GPPSignIn sharedInstance].clientID| must be initialized with a client ID
|
|
|
|
// registered in the Google API console, https://code.google.com/apis/console/
|
|
|
|
// with the app's bundle ID.
|
|
|
|
+ (GPPShare *)sharedInstance;
|
2012-08-25 10:38:29 +00:00
|
|
|
|
|
|
|
// Returns a share dialog builder instance. Call its |open| method to
|
|
|
|
// create the dialog after setting the parameters as needed.
|
2013-01-31 21:22:37 +00:00
|
|
|
- (id<GPPShareBuilder>)shareDialog;
|
2012-08-25 10:38:29 +00:00
|
|
|
|
|
|
|
// This method should be called from your |UIApplicationDelegate|'s
|
|
|
|
// |application:openURL:sourceApplication:annotation|. Returns |YES| if
|
2013-01-31 21:22:37 +00:00
|
|
|
// |GPPShare| handled this URL.
|
2013-04-27 21:14:05 +00:00
|
|
|
// Also see |handleURL:sourceApplication:annotation:| in |GPPURLHandler|.
|
2012-08-25 10:38:29 +00:00
|
|
|
- (BOOL)handleURL:(NSURL *)url
|
|
|
|
sourceApplication:(NSString *)sourceApplication
|
|
|
|
annotation:(id)annotation;
|
|
|
|
|
|
|
|
@end
|