IOS social sharing program summary

I. system native UIActivityViewController

Merits and demerits

  • Advantages: easy to use, do not register complex sharing platform account, do not import bloated SDK package
  • Disadvantages: UI can be poorly customized and can only be used in a fixed style provided by the system. Looks like this. The type of sharing is limited and can only share text, URL, and image.
IOS social sharing program summary
UIActivityViewController sharing interface

Use:

NSString *textToShare = @ "to share text"; UIImage *imageToShare = [UIImage imageNamed:@ "iosshare.jpg"]; NSURL *urlToShare = [NSURL URLWithString:@ "http://www.baidu.com"]; NSArray *activityItems = @[textToShare, imageToShare, urlToShare]; UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil]; [self presentViewController:activityVC animated:YES completion:nil];

ActivityItems is the content to share, including text, pictures, urls. However, it should be noted that not all platforms support the sharing of these three content, such as WeChat can not share pictures and web sites at the same time, the text can not be directly shared, the following figure is a few platforms to share the outline

IOS social sharing program summary
platform sharing summary

When we pop up the view box, we find that there are many icons on the top that we can’t use. We can remove the missing icons, just set the following properties:

ActivityVC.excludedActivityTypes = @[UIActivityTypePostToFacebook, UIActivityTypeAirDrop];

Set up callback block, you can do something after success or failure after sharing,

UIActivityViewControllerCompletionWithItemsHandler = myBlock ^ (UIActivityType __nullable activityType, BOOL completed, NSArray returnedItems NSError * __nullable * __nullable, activityError) {if (completed) {NSLog (@ completed);}}; activityVC.completionWithItemsHandler = myBlock;

Two, system native Social Framework

Merits and demerits

  • Advantages: easy to use, do not register complex sharing platform account, do not import bloated SDK package. UI can draw itself, to meet a lot of personalized needs.
  • Cons: sharing interface UI requires developers to draw their own, increasing the workload. The type of sharing is limited and can only share text, URL, and image.

Use

Import Social.framework

#import < Social/Social.h>
Share / / create controller SLComposeViewController *composeVc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo]; if (composeVc = = Nil) {NSLog (@ "not installed software"); return if;} (! [SLComposeViewController isAvailableForServiceType:SLServiceTypeSinaWeibo]) {NSLog (@ "software is not configured login information"); return;} / / add share text, pictures, links [composeVc setInitialText:@ "to share text"]; [composeVc addImage:[UIImage imageNamed:@ "choice_highlight" [composeVc addURL:[NSURL URLWithString:@ ";" http://www.baidu.com ""; / / [self presentViewController:composeVc animated:YES completion:nil] share pop-up controller; / / monitor the user clicks the cancel is sent composeVc.completionHandl Er ^ (SLComposeViewControllerResult = result) {if (result = = SLComposeViewControllerResultCancelled) {NSLog (@ "click Cancel");} else {NSLog (@ "click send");}};

The system provides only the following sharing platforms:

SLServiceTypeTwitter; SLServiceTypeFacebook; SLServiceTypeSinaWeibo; SLServiceTypeTencentWeibo; SLServiceTypeLinkedIn;

The actual ID can be shared to more platforms, such as WeChat:

NSString *socialType = @ com.tencent.xin.sharetimeline '; SLComposeViewController *composeVC = [SLComposeViewController composeViewControllerForServiceType:socialType];

The reason for this is: after iOS8, the system launched Share Extension, not the system to achieve WeChat share, but the WeChat App Share Extension provides a shared entrance. So this is not a private API, you can rest assured that the use of Extension Share method, all want to get mobile phone with App. Just call the following code..

SLComposeViewController *composeVc = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeSinaWeibo];

Look at the console output. All the available Share Extension bundle Id are out of the phone.

Three, the League of friends and other three parties to share platform

Merits and demerits

  • Advantages: developers can customize, share interfaces, UI, and function in accordance with third party documents. The types of sharing are free to choose, except for text, URL, and image. There are other forms of multimedia (voice, video, documents, etc.) to choose from.
  • Disadvantages: you need to register with friends and other sharing platforms to make complicated accounts and import bloated SDK packages. Configure jump white list.

Use

Sharing documents and SDK Downloads

Four, OpenShare

Merits and demerits

  • Advantages: developers can customize their own sharing interface, UI, functions. The types of sharing are free to choose, except for text, URL, and image. There are other forms of multimedia (voice, video, documents, etc.) to choose from.
  • Cons: you need to configure the jump white list.

Use

Implementation principles introduced
, GitHub code and demo address

summary

Each of these four sharing schemes has its own advantages and disadvantages, and there is no best sharing scheme, only the solution that best suits your App needs.

If you need the App interface customization, sharing types need to support multimedia (voice, video, file sharing platform, etc.) only WeChat, QQ, micro-blog, Alipay, everyone, openshare. If you need to support a lot of platforms, share it with friends.

If the type of sharing is limited to text, image, URL, and the interface requirements are not high, the system’s native UIActivityViewController can use UIActivityViewController. If the interface needs customization, use Social Framework.

programme UI Share type Sharing platform
UIActivityViewController demand moderately Text, image, URL Multiple platforms
Social Framework Custom required Text, image, URL Multiple platforms
League of friends and other three party sharing platform Custom required Support multimedia (voice, video, documents, etc.) Multiple platforms
OpenShare Custom required Support multimedia (sound, video, documents, etc.) WeChat /QQ/ micro-blog / Alipay / everyone

In addition to the first scheme of UIActivityViewController does not need to draw their own interface, other options are to draw their own share pop-up menu, in view of the above problems, the wheels of IFMShare I wrote a highly customizable interface and functionality (Swift version) for your use.

Recommend

IFMShare (Swift version) uses simple and elegant, interface and function highly customizable. Support for single and double row rolling rolling, multi line, squares, head and tail view view a variety of styles, sharing a platform that can directly call the Share Extension, can also use the SDK or OpenShare custom sharing platform. Welcome to issue, pull, request, and star, and the code example is as follows:

IFMShareView *shareView = [[IFMShareView alloc] initWithItems:@[IFMPlatformNameSms, IFMPlatformNameEmail, IFMPlatformNameQQ, IFMPlatformNameWechat], itemSize:CGSizeMake (80100) DisplayLine:YES] [shareView addText:@; / / set share content "share the test"; [shareView addURL:[NSURL "http://www.baidu.com" URLWithString:@ "[shareView addImage:image]; [shareView showFromControlle:self];

Partially custom interface display

IOS social sharing program summary
IOS social sharing program summary
pictures display

GIF show

IOS social sharing program summary
graphical display

Next article: UIActivityViewController custom Activity and OpenShare configuration jump white list


Reference article:

“The use of the system comes with UIActivityViewController and UIActivity for content sharing”
new guide: using Social Framework and UIActivityViewController
iOS by UIActivityViewController
and SLComposeViewController UIActivityViewController share the primary function of
program to share WeChat