Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

standard way to implement share as function

Tags:

ios

share

I need to implement a "share as..." function in iOS. For example a button names "share as..." and popup a dialog which includes items like Email, SMS, Facebook, Twitter. I wonder if there have a standard dialog do this job.

like image 787
mqasll Avatar asked Apr 22 '26 10:04

mqasll


1 Answers

After searching, I found a way seems quite "standard" way in iOS6 by using UIActivityViewController.

Following is the description from developer.apple.com:

The UIActivityViewController class is a standard view controller that you can use to offer various services from your application. The system provides several standard services, such as copying items to the pasteboard, posting content to social media sites, sending items via email or SMS, and more. Apps can also define custom services.

And following is a dialog I managed to produce by using UIActivityViewController

enter image description here

And following is the source code I use:

NSArray *activityItems = [NSArray arrayWithObjects: share_text.text, share_image.image , nil];

    UIActivityViewController *activityController = [[UIActivityViewController alloc] initWithActivityItems:activityItems applicationActivities:nil];
    [self presentViewController:activityController animated:YES completion:nil];
like image 108
mqasll Avatar answered Apr 25 '26 02:04

mqasll



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!