Sharing posts to Google+ from iOS apps

If your want to allow users to share content to Google+ from your app, you can present a Google+ share URL to allow the user to comment on, and share your content.

The following sample demonstrates how to construct such a URL, and present it with a SFSafariViewController on iOS 9+, or mobile Safari on older versions of iOS.

- (void)showGooglePlusShare:(NSURL*)shareURL {

  // Construct the Google+ share URL
  NSURLComponents* urlComponents = [[NSURLComponents alloc]
  urlComponents.queryItems = @[[[NSURLQueryItem alloc]
             value:[shareURL absoluteString]]];
  NSURL* url = [urlComponents URL];

  if ([SFSafariViewController class]) {
    // Open the URL in SFSafariViewController (iOS 9+)
    SFSafariViewController* controller = [[SFSafariViewController alloc]
    controller.delegate = self;
    [self presentViewController:controller animated:YES completion:nil];
  } else {
    // Open the URL in the device's browser
    [[UIApplication sharedApplication] openURL:url];

Enviar comentarios sobre…

Google+ Platform for iOS
Google+ Platform for iOS