Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIActivityViewController duplicate url in iOS-11

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
like image 845
Hani Ibrahim Avatar asked Sep 26 '17 10:09

Hani Ibrahim


1 Answers

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

let items: [Any] = [shareText, url.absoluteString]
like image 189
Hani Ibrahim Avatar answered Oct 15 '22 13:10

Hani Ibrahim