Google+ Platform for iOS

Sharing to Google+ from your iOS app

The Share dialog provides a means for users to share rich content from your app into the Google+ stream, including text, photos, and URL attachments. The code examples in this page demonstrate how to display and share content with a native share dialog within your app. The native share dialog requires that you use Google+ Sign-In in your app and ensures that your visitors stay in your app in context while sharing content.

A
  screenshot of in-app native sharing.
The native share dialog displays within your app
A screenshot of in-app native sharing suggestions.
The native share dialog also offers sharing suggestions to a user.

Additional examples demonstrate how to share interactive posts, upload media with posts, use deep linking, use basic sharing for anonymous users, and detect if posts are shared successfully.

Before you begin

You must create a Google APIs Console project and initialize the Google+ client. If you plan on building deep linking into your app, you must create a client ID for each platform that you plan on supporting within the same APIs Console project.

The native sharing dialog requires that you use Google+ Sign-In and request the https://www.googleapis.com/auth/plus.login (kGTLAuthScopePlusLogin).

Add native sharing

To integrate the Google+ share in your application, add a UIButton and configure it with these steps:

  1. In your ViewController, set the target of your UIButton to an IBAction, which is didTapShare in the example below.

    - (IBAction) didTapShare: (id)sender {
      // Share builder code will go here
    }
    
  2. Create a share dialog builder instance by calling GGPShare's nativeShareDialog method, and then call open to open it. This example brings up a mostly-empty share dialog using the native share dialog.

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

Sharing a URL

When you share a URL, the title, thumbnail image, and link for the share dialog are based on the URL you provide. You specify this URL by using the GPPShareBuilder's setUrlToShare method.

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

      // This line will fill out the title, description, and thumbnail from
      // the URL that you are sharing and includes a link to that URL.
      [shareBuilder setURLToShare:[NSURL URLWithString:@"https://www.example.com/restaurant/sf/1234567/"]];

      [shareBuilder open];
    }

If you have trouble configuring the preview of the shared content based on the URL, see the snippet documentation.

Additional sharing options

You might also want to explore the following approaches to sharing content from your app:

Next steps

After you implement sharing in your app, you might consider implementing the following features:

Authentication required

You need to be signed in with Google+ to do that.

Signing you in...

Google Developers needs your permission to do that.