func pickerView(sender : UIButton) {
    let message="text"
    let objectsToShare = [message]
    let wsActivity = WhatsAppActivity()


    let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: [wsActivity])
    activityVC.excludedActivityTypes = [UIActivityTypeAirDrop, UIActivityTypeAddToReadingList,UIActivityTypeCopyToPasteboard,UIActivityTypeSaveToCameraRoll,UIActivityTypePrint]

    self.presentViewController(activityVC, animated: true, completion: nil)
}

如何使用Facebook Messenger进行同样的操作?

最佳答案

就我的研究而言,你不能在FB信使中共享“字符串”。这与FB messenger策略有关(此策略的链接引用丢失)。要在Facebook Messenger上共享,您的“activityitems:objectstoshare”应包含nsurl。我尝试共享多个nsrul,但没有成功。
可以传递一个[string,nsurl]数组,例如:

func pickerView(sender : UIButton) {
     let message="text"
     let url = NSURL(String: "https://www.google.com")!
     let objectsToShare = [message, url]  //this is now an [AnyObject]
     //assuming you are don't have applications to exclude

     let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: [wsActivity])
     self.presentViewController(activityVC, animated: true, completion: nil)
}

你会发现WhatsApp和FB Messenger都出现在你的分享表中。但是,fb messenger将只使用nsurl-its,而忽略anyobject数组中的字符串项。whatsapp将显示文本和链接。
您可能可以使用fb sdk执行您想要的操作。但我没有亲自尝试过。

关于swift - 如何在事件 Controller View 中显示Facebook Messenger应用程序以发送消息?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33169724/

10-12 00:40