IOS through the UIActivityViewController to achieve the primary sharing function

The first thing to say is that why so many sharing platform, you can directly integrate the sharing function of each platform, but also to achieve the system’s native sharing function. No way, WeChat share function is greatly disabled, designed to induce users to share, it can only be a circle around the content sharing out, and will not affect the function of APP (now share will get paid), UIActivityViewController came out, this is a system with the original share function, we must in the album pictures can be used frequently, we need to share the video platform, or saved to the system clipboard, memo etc..
1 simple implementation

NSString *textToShare = @ "to share text"; UIImage *imageToShare = [UIImage imageNamed:@ "iosshare.jpg"]; NSURL *urlToShare = [NSURL URLWithString:@ ""]; NSArray *activityItems = @[textToShare, imageToShare, urlToShare]; UIActivityViewController *activityVC = [[UIActivityViewController alloc]initWithActivityItems:activityItems applicationActivities:nil];
IOS through the UIActivityViewController to achieve the primary sharing function

emulator screenshot all no WeChat icon.

2 parameters introduced
activityItems is to share the content, including pictures, pictures, web site.
but this note is not supported on all platforms of the three content sharing, such as WeChat, can share pictures and text. At the same time, not directly to share the platform to share several roughly

IOS through the UIActivityViewController to achieve the primary sharing function
platform to share.Png

The second parameter of the
is an array of UIActivity objects representing a custom service supported by the application. This parameter can be nil.
when the pop-up view box, we found a lot of icons on the top is that we can not use, we can use the icon to get rid of the use of the function is

ActivityVC.excludedActivityTypes = @[UIActivityTypePostToFacebook, UIActivityTypePostToTwitter, UIActivityTypePostToWeibo, UIActivityTypeMessage, UIActivityTypeMail, UIActivityTypePrint, UIActivityTypeCopyToPasteboard, UIActivityTypeAssignToContact, UIActivityTypeSaveToCameraRoll, UIActivityTypeAddToReadingList, UIActivityTypePostToFlickr, UIActivityTypePostToVimeo, UIActivityTypePostToTencentWeibo, UIActivityTypeAirDrop, UIActivityTypeOpenInIBooks];

The above is to be able to get rid of the hidden, the above is the default function of the system.
to achieve this we found that this function can be divided into two categories, and share in the share class, we can share our three party platform, you can also share the album system platform, in that class, we can find that we can save the text to the clipboard, news etc..
4 share after the callback
callback has two functions, first said the first

UIActivityViewControllerCompletionHandler = myBlock ^ (NSString *activityType, BOOL completed) {NSLog (@ activityType:% @ ", activityType); if (completed) {NSLog (@ completed);} else {NSLog (@ cancel);} completionHandler, when after the end of post (either done or cancell) of the blog will be called activityVC.completionHandler = myBlock;

There is also a callback

Typedef void (^UIActivityViewControllerCompletionWithItemsHandler) (UIActivityType __nullable activityType, BOOL completed, NSArray * __nullable returnedItems, NSError * __nullable activityError);

ReturnedItems is a NSExtensionItem object containing the array; activityError
pointed out that the cause of the error when we share success or partial cancellation, are calling the block function
: activityType is to share what platform is a platform, if the system will, enumeration class printing system name, WeChat and other three party platform will print
after the success of completed is YES or NO. We call the code we need to execute after success or failure.
5 supplement
UIActivity can be customized, the icon above and buttons can customize their own, you can also achieve the docking with the major sharing platform. Temporarily not used, so there is no specific implementation.

The realization of a simple function that is, learning, share with you.