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进行相同的操作?
答案 0 :(得分:2)
就我的研究而言,你不能在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,并忽略AnyObject数组中的String项。 WhatsApp将显示文本,然后显示链接。
您可能能够使用FB SDK执行您想要执行的操作。我个人没试过。
答案 1 :(得分:0)
如果您想在UIActivityViewController
中展示Facebook应用
而不是指定任何excludedActivityTypes
属性。
因为excludedActivityTypes: [String]? //default is nil
。`
所以只需用作
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: [wsActivity])
self.presentViewController(activityVC, animated: true, completion: nil)
它会显示所有选项,包括facebook,twitter ext。