8

The url is duplicated when the user choose "Copy" from the activity controller in iOS 11 only. It was working properly on iOS 10

Using the below code

@IBAction func shareButtonPressed() {
    guard let url = URL(string: "http://google.com") else { return }
    let shareText = "Share Text!"
    let items: [Any] = [shareText, url]
    let activityViewController = UIActivityViewController(activityItems: items, applicationActivities: nil)
    present(activityViewController, animated: true, completion: nil)
}

gives the shared text as:

Share Text! 
http://google.comhttp://google.com
Hani Ibrahim
  • 1,448
  • 11
  • 21

1 Answers1

2

I managed to fix it by using the url as String instead of URL.

let items: [Any] = [shareText, url.absoluteString]
Hani Ibrahim
  • 1,448
  • 11
  • 21
  • 1
    I have the same problem, but this fix is not right, because some activity needs to recognize URL as NSURL not string. – iTarek Oct 05 '17 at 14:05
  • Yeah, this solution is not ideal for sure. But it may fix some situation and not for other cases... sorry that it didn’t help you. Please post your answer if you find a better solution – Hani Ibrahim Oct 05 '17 at 18:07