Summary of social sharing solutions for iOS

Summary of social sharing solutions for iOS

1. System native UIActivityViewController

Pros and Cons

  • Advantages: Easy to use, no need to register complicated sharing platform accounts, no need to import bloated SDK packages
  • Disadvantages: UI customizability is poor, and only fixed styles provided by the system can be used, which look like the following. The types of sharing are limited, and only text, URL, and image can be shared.

UIActivityViewController sharing interface

use:

  1. NSString *textToShare = @ "text content to be shared" ;
  2. UIImage *imageToShare = [UIImage imageNamed:@ "iosshare.jpg" ];
  3. NSURL *urlToShare = [NSURL URLWithString:@ "http://www.baidu.com" ];
  4.   
  5. NSArray *activityItems = @[textToShare, imageToShare, urlToShare];
  6. UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
  7.   
  8. [self presentViewController:activityVC animated:YES completion:nil];

ActivityItems is the content to be shared, including text, pictures, and URLs. However, it should be noted that not all platforms support sharing of these three types of content. For example, WeChat cannot share pictures and URLs at the same time, and text cannot be shared directly. The following figure is a summary of sharing on several platforms

Overview of sharing on each platform

When the view box pops up, we find that many of the icons on it are not used by us. We can remove the icons that we don’t need by setting the following properties:

  1. activityVC.excludedActivityTypes = @[UIActivityTypePostToFacebook,UIActivityTypeAirDrop];

Set a callback block to do something after sharing succeeds or fails.

  1. UIActivityViewControllerCompletionWithItemsHandler myBlock = ^(UIActivityType __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError) {
  2.          
  3. if (completed){
  4. NSLog(@ "completed" );
  5. }
  6. };
  7.   
  8. activityVC.completionWithItemsHandler = myBlock;

2. System-native Social Framework

Pros and Cons

  • Advantages: Easy to use, no need to register complicated sharing platform accounts, no need to import bloated SDK packages. UI can be drawn by yourself, meeting many personalized needs.
  • Disadvantages: The UI of the sharing interface needs to be drawn by the developer, which increases the workload. The sharing type is limited, and can only share text, URL, and image.

use

Import Social.framework

  1. #import
  2. //Create a shared controller
  3. SLComposeViewController *composeVc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];
  4.   
  5. if (composeVc == nil){
  6. NSLog(@ "Software not installed" );
  7. return ;
  8. }
  9.   
  10. if (![SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) {
  11. NSLog(@ "The software is not configured with login information" );
  12. return ;
  13. }
  14.   
  15. //Add shared text, pictures, links
  16. [composeVc setInitialText:@ "text content to be shared" ];
  17. [composeVc addImage:[UIImage imageNamed:@ "choice_highlight" ]];
  18. [composeVc addURL:[NSURL URLWithString:@ "http://www.baidu.com" ]];
  19.   
  20. //Pop up the sharing controller
  21. [self presentViewController:composeVc animated:YES completion:nil];
  22.   
  23. //Monitor whether the user clicks cancel or send
  24. composeVc.completionHandler = ^(SLComposeViewControllerResult result){
  25. if (result == SLComposeViewControllerResultCancelled) {
  26. NSLog(@ "Clicked cancel" );
  27. } else {
  28. NSLog(@ "Clicked send" );
  29. }
  30. };

The system only provides the following sharing platforms:

  1. SLServiceTypeTwitter;
  2.  
  3. SLServiceTypeFacebook;
  4.  
  5. SLServiceTypeSinaWeibo;
  6.  
  7. SLServiceTypeTencentWeibo;
  8.  
  9. SLServiceTypeLinkedIn;

In fact, you can share it to more platforms based on the ID, such as WeChat:

  1. NSString *socialType = @ "com.tencent.xin.sharetimeline" ;
  2.  
  3. SLComposeViewController *composeVC = [SLComposeViewControllercomposeViewControllerForServiceType:socialType];

The reason why it can be used in this way is that the Share Extension launched by the system after iOS8 does not implement WeChat sharing by the system, but the Share Extension of the WeChat App provides a sharing entrance. Therefore, this is not a private API and can be used with confidence. If you want to obtain all the Share Extension methods of the Apps installed on your phone, just call the following code.

  1. SLComposeViewController *composeVc = [SLComposeViewControllercomposeViewControllerForServiceType:SLServiceTypeSinaWeibo];

Looking at the console output, the bundle IDs of all available Share Extensions in the phone are displayed.

3. Third-party sharing platforms such as Umeng

Pros and Cons

  • Advantages: Developers can customize the sharing interface UI and functions according to third-party documents. The sharing type can be freely selected, in addition to text, URL, image. There are also other formats of multimedia (sound, video, file, etc.) to choose from.
  • Disadvantages: You need to register complicated accounts on Umeng and various sharing platforms, import bloated SDK packages, and configure the jump whitelist.

use

Umeng shares usage documentation and SDK downloads (http://dev.umeng.com/social/ios/operation)

4. OpenShare

Pros and Cons

  • Advantages: Developers can customize the sharing interface UI and functions. The sharing type can be freely selected, in addition to text, URL, image. There are also other formats of multimedia (sound, video, file, etc.) to choose from.
  • Disadvantage: A jump whitelist needs to be configured.

use

  • Implementation principle introduction

http://www.gfzj.us/series/openshare/

  • github code and demo address

https://github.com/100apps/openshare

Summarize

These four sharing solutions have their own advantages and disadvantages. There is no best sharing solution, only the one that best suits your App needs.

If your App interface needs to be customized, the sharing type needs to support multimedia (sound, video, files, etc.), and the sharing platform is limited to WeChat, QQ, Weibo, Renren, and Alipay, use openshare. If you need to support many platforms, use Umeng sharing.

If the sharing type is limited to text, image, and URL, and the interface requirements are not high, the system's native UIActivityViewController can be used. If the interface needs to be customized, use the Social Framework.

plan UI Sharing Type Sharing Platform
UIActivityViewController Not demanding text, image, url Multiple platforms
Social Framework Request Customization text, image, url Multiple platforms
Umeng and other third-party sharing platforms Request Customization Support multimedia (sound, video, files, etc.) Multiple platforms
OpenShare Request Customization Support multimedia (sound, video, files, etc.) WeChat/QQ/Weibo/Renren/Alipay

Except for the first solution where UIActivityViewController does not need to draw its own interface, other solutions require you to draw the share pop-up menu yourself. To solve the above problems, I wrote a wheel IFMShare (Swift version) with highly customizable interface and functions for everyone to use.

recommend

IFMShare (Swift version) is simple and elegant to use, and its interface and functions are highly customizable. It supports multiple styles such as single-line scrolling, double-line scrolling, multi-line, nine-square grid, header view, footer view, etc. The sharing function can directly call Share Extension with a platform name, or use the SDK of each platform or OpenShare to customize the sharing function. Welcome to issue, pull request, star, the code example is as follows:

  1. IFMShareView *shareView = [[IFMSareView alloc] initWithItems:@[IFMPlatformNameSms,IFMPlatformNameEmail,IFMPlatformNameQQ,IFMPlatformNameWechat] itemSize:CGSizeMake(80,100) DisplayLine:YES];
  2. //Set the shared content
  3. [shareView addText:@ "Share test" ];
  4. [shareView addURL:[NSURL URLWithString:@ "http://www.baidu.com" ]];
  5. [shareView addImage:image];
  6.      
  7. [shareView showFromControlle:self];

Partial custom interface display

Picture Show

GIF display

Animated picture display

Reference articles:

《Use the system's own UIActivityViewController and UIActivity to share content》

Beginner's Guide: Using Social Framework and UIActivityViewController

iOS implements native sharing function through UIActivityViewController

UIActivityViewController and SLComposeViewController

Share to WeChat within the app

<<:  Apple's 3D recognition is two years ahead of Qualcomm, but Android manufacturers are not interested in mobile phone 3D

>>:  The third episode of the Aiti Tribe live class: the first case in China to talk about the practice of MySQL InnoDB memcached plugin

Recommend

Mainstream App promotion and customer acquisition channels and methods!

With the development of App development technolog...

Sorry, I don't like programming, I like creating

I don't know if it's because people are r...

Has Taobao's "QuA" revolutionized online travel?

Taobao gave birth to another son, named "QuA...

12 tips for writing titles for new media operations!

Writing a headline is like having a difficult lab...

How to create efficient and high-quality ground promotion?

2014 was a boom year for mobile healthcare. Accor...

The "Thirty-Six Strategies of Operations" are, after all, a "trap."

Recently, the Internet finance industry and campu...

After several major WeChat updates, you may not know these 8 useful tips

WeChat may be the most frequently used app in eve...

iOS event response chain and event delivery principle

In iOS applications, one of the core mechanisms f...