UIActivityViewController在iOS-11中复制url

时间:2017-09-26 10:44:23

标签: swift uiactivityviewcontroller ios11

当用户选择"复制"时,网址会重复。仅来自iOS 11中的活动控制器。它在iOS 10上正常运行

使用以下代码

@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)
}

将共享文本提供为:

Share Text! 
http://google.comhttp://google.com

1 个答案:

答案 0 :(得分:2)

我设法通过将url用作String而不是URL来修复它。

let items: [Any] = [shareText, url.absoluteString]