About iOS Sharing

About iOS Sharing

2018, Jun 04    

This article introduces some generic strategies which can be used to integrate multi social platform into a lightweight shairng SDK.

Strategy 1: Using the iOS UIAcitivityViewController

To get full information, please visit apples documentation.

- (void)shareText:(NSString*)text andImage:(UIImage*)image andUrl:(NSURL*)url
{

  NSMutableArray* sharingItems = [NSMutableArray new];
  // Alternatives 1: passing raw information like texts, images
  // append text  
  if (text) { [sharingItems addObject:text]; }

  // append image
  if (image) { [sharingItems addObject:image]; }

  // append url
  if (url) { [sharingItems addObject:url]; }

  // Alternatives 2: passing instance of UIActivityItemProvide,
  // where you can specify the activity type(like sms, phone, twitter, facebook)
  // may refer to: https://developer.apple.com/documentation/uikit/uiactivityitemprovider

  UIActivityViewController* activityController = [[UIActivityViewController alloc] initWithActivityItems:sharingItems
                                                                                   applicationActivities:nil];
  [self presentViewController:activityController animated:YES completion:nil];
}

To design your own sharing feature for your app, you can refer to this article. However there are also drawbacks on this, which relies on the installation of the app and also requires the sharing app needs to implement the sharing extension.

Strategy 2: Using your own sharing kit

Here is the overall design principle for each of the sharing channel if you want to build your own sharing kit:

  • If the platform you are going to share to has been installed in the device:
    • If no need extra SDK and then can already share it to the app, adopt schema or universal link to share it.
    • If need extra SDK, then can see whether there is web api for it.
  • If the platform you are going to share has not been installed, invoke your own web-view widget to share it via the platform’s web api.

The following table lists down how to share to: facebook, twitter, instagram, whatsapp, email, messenger

Sharing Platform Is relevant App installed Strategies
facebook YES consider using facebook’s internal schema
facebook NO in the customised UIWebView widget calling facebook’s web api
facebook messenger YES consider using facebook messenger’s api here
facebook messenger NO using same web api provided by facebook web
twitter YES consider using twitter’s schema
twitter NO in the customized webview calling the twitter’s web api
instagram YES consider using instagram’s schema
instagram NO in the customized webview calling the instagram’s web api
whatsapp YES consider using whatsapp’s schema
whatsapp NO in the customized webview calling the whatsapp’s web api
email N.A. apple’s reference
sms N.A. apple’s reference
TOC