Ios8 - how to show the common stock by default

I want to introduce and use the default “share to other service” leaflet to allow sharing on twitter, facebook, email, etc.

I can't figure out how to show this view from my application - how can I do this?

+6
source share
3 answers

You can use a simple activity controller to display default sharing applications using:

NSArray *activityItems = [NSArray arrayWithObjects:shareString, shareImage, shareUrl, nil]; UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil]; activityViewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical; [self presentViewController:activityViewController animated:YES completion:nil]; 

And you can also use the completion handler:

 [activityViewController setCompletionHandler:^(NSString *act, BOOL done) { //Code here when the action performed. }]; 

This will show all default sharing apps.

+19
source

Here is the solution for the "share" popup that starts with UIBarButtonItem , which works on both iPhone and iPad:

 // "Share" action - (IBAction)share:(UIBarButtonItem *)sender { NSString* title = "Content Title"; NSString* link = "http://example.com/content.url"; NSArray* dataToShare = @[title, link]; UIActivityViewController* activityViewController = [[UIActivityViewController alloc] initWithActivityItems:dataToShare applicationActivities:nil]; // This is key for iOS 8+ activityViewController.popoverPresentationController.barButtonItem = sender; [self presentViewController:activityViewController animated:YES completion:^{}]; } 
+3
source

Here is one simple example:

 let activityViewController = UIActivityViewController(activityItems: ["Share Me!"], applicationActivities: nil) activityViewController.completionWithItemsHandler = { [weak self] activityType, completed, returnedItems, activityError in // Note: you won't need returnedItems in most cases // It is included in this example for completion sake } present(activityViewController, animated: true, completion: nil) 

Full documentation of the completion handler is available here: https://developer.apple.com/documentation/uikit/uiactivityviewcontrollercompletionwithitemshandler

0
source

Source: https://habr.com/ru/post/978306/


All Articles