如何共享社交应用程序的URL Scheme链接

时间:2016-01-20 08:15:27

标签: ios

我想分享一个到社交应用程序的URL方案链接,这样当用户在safari上打开社交页面时,当他们点击链接时,URL方案将调用我设置的应用程序。但是当我分享时,它只分享文本。如何共享链接而不是文本。

enter image description here

以下是代码:

@IBAction func shareButtonAction(sender: AnyObject) {
        print("share")
        let myShare = "TestSafari://"
        let shareVC: UIActivityViewController = UIActivityViewController(activityItems: [myShare], applicationActivities: nil)
        self.presentViewController(shareVC, animated: true, completion: nil)
    }

2 个答案:

答案 0 :(得分:0)

您可能需要先按照特定顺序放置文本,然后放置网址。试试这个:

let string: String = ...
let URL: NSURL = ...
let shareVC = UIActivityViewController(activityItems: [string, URL])

答案 1 :(得分:0)

let activityViewController = UIActivityViewController(
            activityItems: [image],
            applicationActivities: nil)
        activityViewController.excludedActivityTypes = [UIActivityTypeMessage,UIActivityTypeMail,UIActivityTypeCopyToPasteboard,UIActivityTypeAirDrop];
        presentViewController(activityViewController, animated: true, completion: nil)

将此代码用于Present ActivityViewController,只将activityItems更改为您的字符串。