Reputation: 1216
I'm struggling to get my application to share a URL properly so that the "Open in Safari" and "Open in Chrome" activity items show up in the share sheet. I've tried sharing the URL a few different ways:
NSURL *data = _article.url;
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[data] applicationActivities:nil];
For reference, these are the two activity items I'm trying to get to show up.
Upvotes: 16
Views: 4984
Reputation: 2062
There a few (small) libraries you can use that provide custom UIActivity
controls to get the "Open in Safari" and "Open in Chrome" activity items.
Chrome: ARChromeActivity
@IBAction func shareClick(_ sender: Any) {
var sharingItems = [AnyObject]()
var sharingActivities = [UIActivity]()
sharingItems.append(URL(string: shareURL)! as AnyObject)
sharingActivities.append(TUSafariActivity())
sharingActivities.append(ARChromeActivity())
let activityViewController = UIActivityViewController(activityItems: sharingItems, applicationActivities: sharingActivities)
activityViewController.popoverPresentationController?.barButtonItem = self.navigationItem.rightBarButtonItem;
self.present(activityViewController, animated: true, completion: nil)
}
Even more custom UIActivity
controls can be found on https://github.com/shu223/UIActivityCollection
Upvotes: 5
Reputation: 1216
It appears there is a very popular library "SVWebViewController" for displaying in app web views. The library also contains some nice activity items that you can use to do this.
https://github.com/TransitApp/SVWebViewController
Here is an example of the code you can use to make it work (don't forget to include the headers in your code as well)
#import "SVWebViewControllerActivityChrome.h"
#import "SVWebViewControllerActivitySafari.h"
- (void)share:(id)sender {
NSArray *activities = @[[SVWebViewControllerActivitySafari new], [SVWebViewControllerActivityChrome new]];
UIActivityViewController *activityViewController = [[UIActivityViewController alloc] initWithActivityItems:@[_article.url] applicationActivities:activities];
}
Upvotes: 3