I use the UIActivityViewController to share the UIActivityViewController URL in iOS 11 , and when using Copy then go to the Messages app, then paste it twice.
Out of curiosity, I tried to do the same with Safari, Chrome, Firefox, as well as for applications other than messages. The result was interesting:
- Using Safari always works in any application.
- Working with Chrome or FireFox works in the Notes application, but it duplicates the copied text in any application with TextField (messages, WhatsApp, Slack, Signal, ...)
Here is my simple code
func shareURL(title: String, url: URL) { var activityItems = [AnyObject]() activityItems.append(TitleActivityItemProvider(title: title)) activityItems.append(url as AnyObject) let activityViewController = UIActivityViewController(activityItems: activityItems, applicationActivities: nil) self.present(activityViewController, animated: true, completion: nil) }
and here is the class TitleActivityItemProvider
class TitleActivityItemProvider: UIActivityItemProvider { static let activityTypesToIgnore = [UIActivityType.copyToPasteboard] init(title: String) { super.init(placeholderItem: title) } override var item : Any { if let activityType = activityType { if TitleActivityItemProvider.activityTypesToIgnore.contains(activityType) { return NSNull() } } return placeholderItem! as AnyObject } override func activityViewController(_ activityViewController: UIActivityViewController, subjectForActivityType activityType: UIActivityType?) -> String { return placeholderItem as! String } }
is this a bug on iOS 11 , or should I make specific changes when working with the UIActivityViewController
== UPDATE ==
I noticed when commenting on the addition of TitleActivityItemProvider , it works fine, and when I add it, it duplicates the URL, however I ignore UIActivityType.copyToPasteboard in the header provider and return NSNull()
ios swift3 ios11 uiactivityviewcontroller
Mahmoud adam
source share