How do I customize a UIActivityViewController to show a URL link when posting to facebook and twitter?

后端 未结 4 1262
礼貌的吻别
礼貌的吻别 2020-12-14 07:08

So I\'m trying out the new UIActivityViewController in iOS 6, and it\'s really easy to get up and running, but I can\'t figure out how to control it like I want

4条回答
  •  南方客
    南方客 (楼主)
    2020-12-14 08:00

    Updated the answer for Swift 3.0

    let url = URL(string: "google.com")
    let shareText = "Your string goes here"
    let shareItems: [Any] = [shareText, url!]
    
    let activityVC = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
    activityVC.excludedActivityTypes = [.airDrop, .postToFlickr, .assignToContact, .openInIBooks]
    
    self.present(activityVC, animated: true, completion: nil)
    

    Facebook won't accept the string, but, like many other of the social media sites, will show an image/link box for the URL

提交回复
热议问题