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.
View a webpage open on another device 1 In the Safari app on your Mac, click the “Show tab overview” button .#N#You can see the webpages open on your Mac along... 2 Click a webpage to open it.#N#Tip: You can also enter part of the page’s name in the Smart Search field, then click the... More ...
How to Put Safari Icons on Your Home Screen Open Safari and go to a website you visit frequently. Tap the Share icon at the bottom of the screen. Scroll across the bottom row of icons in the Sharing window and tap Add to Home Screen. Next to the icon that will represent this website is a name field.
In the Safari app on your Mac, click the Tab Overview button . You can see the webpages open on your Mac along with lists of the webpages open on your other devices. Click a webpage to open it.
On this screen, locate the ‘Shared with You’ toggle, and when you do, tap and hold the Hamburger icon. You can now drag this section downwards to hide it further below the Safari Start page and drop it to your desired location. When done, you should see the Shared with You option at the bottom and its section much lower inside the Start Page.
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];
}
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With