UIActivityViewController copy element twice on iOS 11

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()

+7
ios swift3 ios11 uiactivityviewcontroller
source share
2 answers

So I fixed it using url.absoluteString when adding an element to activityItems

 activityItems.append(url.absoluteString as AnyObject) 
+1
source share

Are you testing a simulator? On the simulator, I had this problem, but on the device it only inserts once.

0
source share

All Articles