Adding deep linking to Google+ posts shared from your iOS app

Deep linking allows the Google+ app on mobile devices to direct clicks on a shared post that contains deep link information to a resource within your mobile app if the user has it installed. If the user does not have your app installed, they are prompted to install it before accessing the resource. Deep linking can be used on shared basic posts and shared interactive posts.

1. Create a client ID for each supported platform

  1. In the Google API Console, select APIs & auth > Credentials.
  2. In Start integrating Google+ into your iOS app, you created an OAuth 2.0 client ID for iOS. To enable deep linking, select Edit settings for this client ID, then select Enable in the Deep Linking section of the dialog.
  3. Select Update to save your change.

  4. If you are supporting additional platforms (Android or Web), register an app for each platform in this same API Console project. If you are also creating a native Android app, enable deep linking for that client ID.

If you specify a logo for your app in the Consent Screen section, your logo might be displayed in any post to help users identify the origin and target of the post. By using the sharing feature, you agree that Google can display the name of your app and your logo within Google's products and services.

Deep links require an identifier that your app defines for use across its supported platforms to identify the correct deep-link view to launch in your app. In addition, for content deep links you must either specify a URL from which Google will retrieve the content to render the share preview, or specify data for the title, description, and thumbnail URL.

You can build content deep links in two ways:

  • Passing a URL to setURLToShare: and passing a deep-link identifier to setContentDeepLinkID:. Google retrieves the content at the URL and extracts from it a title, description and thumbnail URL to populate the share dialog.
  • Passing the title, description, and thumbnail URL to setTitle:description:thumbnailURL: and passing a deep-link identifier to setContentDeepLinkID:. Choose this approach when you do not have a URL to retrieve the information to populate the share dialog.

The deep-link identifier must be 512 or fewer characters, and should not contain any invalid characters or character sequences for a URL. This could be any arbitrary string, or a fully qualified URL, depending on your application's needs. For example, "HelloWorld", "4815162342" or "" are all considered valid deep-link identifiers, but not "hello world" (space) or "hello%2Xworld" (bad escape sequence). If you are using an arbitrary string for your deep link identifier, you might consider base64-encoding it to ensure it contains only valid characters.

3. Sharing with deep linking

Configure the deep-link identifier. This is an opaque string that will be passed to your native mobile application if the user follows the link on the appropriate device. You can set this deep-link identifier by calling your GPPShareBuilder's setContentDeepLinkId method.

- (IBAction) didTapShare: (id)sender {
  id<GPPNativeShareBuilder> shareBuilder = [[GPPShare sharedInstance] nativeShareDialog];

  // This line will fill out the title, description, and thumbnail of the item
  // you're sharing based on the URL you included.
  [shareBuilder setURLToShare:[NSURL URLWithString:@""]];

  [shareBuilder setPrefillText:@"I made reservations!"]

  // This line passes the string "rest=1234567" to your native application
  // if somebody opens the link on a supported mobile device
  [shareBuilder setContentDeepLinkID:@"rest=1234567"];

  [shareBuilder open];

Next, you must configure your app to handle the incoming deep links to direct visitors to the correct location within your app.

  1. Handle incoming deep links to direct visitors to the correct location within your app.

When a user clicks on a shared post that contains deep link data for your app, the app launches if installed, or the user is prompted to install your app. The Google+ app directs deep links to the appropriate app based on the platform that the user is browsing. For example, if they are using Android and you have an Android app registered in the API Console, the Google+ app will launch your Android app and pass the deep-link identifier, which your app can use to direct the user to the correct location within your app. These deep links work across platforms: an interactive post generated from your iOS app can launch your Android app on an Android user's device.

When the app launches, it needs to check if the deep-link information is available and launch the correct view in the app.

  1. In your app delegate's .h file, import GooglePlus/GooglePlus.h, and add the GPPDeepLinkDelegate protocol:

    #import <GooglePlus/GooglePlus.h>
    @interface AppDelegate : UIResponder <UIApplicationDelegate, GPPDeepLinkDelegate>
  2. In your app delegate's applicationDidFinishLaunching:withOptions method, set the GPPDeepLink's delegate, and check for incoming deep links by calling readDeepLinkAfterInstall:

    - (BOOL)application: (UIApplication *)application didFinishLaunchingWithOptions: (NSDictionary *)launchOptions
      [GPPDeepLink setDelegate:self];
      [GPPDeepLink readDeepLinkAfterInstall];
      return YES;
  3. To process incoming deep-link URLs, call GPPURLHandler's handleURL method from your app delegate's URL handler.

      - (BOOL)application: (UIApplication *)application
                  openURL: (NSURL *)url
        sourceApplication: (NSString *)sourceApplication
               annotation: (id)annotation {
       return [GPPURLHandler handleURL:url
  4. Handle the incoming deep link in your app delegate by implementing the didRedceiveDeepLink method, which is part of the GPPDeepLinkDelegate protocol. This method is where you can perform any application logic based on the deep-link identifier that the app receives.

    - (void)didReceiveDeepLink: (GPPDeepLink *)deepLink {
      // An example to handle the deep link data.
      UIAlertView *alert = [[UIAlertView alloc]
                             initWithTitle:@"Deep-link Data"
                                   message:[deepLink deepLinkID]
      [alert show];

If you also have an Android app, you should handle the incoming deep-links in that app too. Deep-link is cross-platform and the Google+ app will launch your app on the correct platform for the user if it is installed or will prompt the mobile user to install your app if it is not currently installed.

Next steps

Enviar comentarios sobre…

Google+ Platform for iOS
Google+ Platform for iOS