Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS native way to share files to any possible apps

I'm currently implementing an iOS app using objective-C, which has a function that users may share a file with other friend or other app (like upload the file to Dropbox, Google Drive, attach the file to Mail, share the file to Facebook Messenger, Whatsapp, via Bluetooth, etc).

Is there a native way to implement this share function that can detect all apps which allows sharing a file, while I don't need to do it one by one?

like image 972
Ken Chan Avatar asked Oct 19 '25 01:10

Ken Chan


1 Answers

You want to use UIActivityViewController. Below is an example from NSHipster, which is probably the most comprehensive article I've seen on the subject. And Apple has some good documentation here.

NSString *string = ...;
NSURL *URL = ...;

UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[string, URL]
                                applicationActivities:nil];
[navigationController presentViewController:activityViewController
                                  animated:YES
                                completion:^{
     // ...
}];
like image 129
Jeff Wolski Avatar answered Oct 21 '25 16:10

Jeff Wolski



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!