分享不适用于Whatsapp和Facebook - 快速项目

时间:2016-05-10 08:25:12

标签: ios swift facebook share whatsapp

我正在使用swift和firebase开发iOS应用程序。

我尝试添加共享功能,用户可以在其中将一些信息从firebase共享到社交网络应用。

这是我添加的按钮:

     @IBAction func text2share(sender: AnyObject) {
    let text2share = "Check out this ✨ \r\n Business Name:  \(self.BusinessNameL.text!)  \r\n Phone: \(self.PhoneNumberTV.text!) \r\n Category: \(self.CategoryL.text!) \r\n Website: \(self.Website1TV.text!) \r\n in Business Wallet app "
    let objects2Share = [text2share]
    let activityVC = UIActivityViewController(activityItems: objects2Share, applicationActivities: nil)
    self.presentViewController(activityVC, animated: true, completion: nil)
}

当我尝试它时,除了whatsapp和Facebook之外,它适用于所有社交网络应用程序!

*这是我尝试与whatsapp分享时出现的错误: enter image description here

*这里是我分享到Facebook时得到的: enter image description here 链接是空的!

有谁知道如何解决这个问题? 为什么会这样?

2 个答案:

答案 0 :(得分:1)

这是关于whatsapp的错误。

检查一下 thread。它讨论了同样的问题。这似乎是一个非常近期的错误,因为之前使用的方法相同。由santhu检查this answer是否有可能的解决方法或等待,因为他们已经承认解决了这个错误。

如果您尝试此代码,则可以只分享我正在谈论的网址。

    let textToShare = "Check out this  Business Name"
    let appURL = NSURL(string: "http://www.google.com")! as NSURL
    let objectsToShare = [textToShare, appURL]
    let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)

    //New Excluded Activities Code
    activityVC.excludedActivityTypes = [UIActivityTypeAirDrop, UIActivityTypeAddToReadingList]
    self.presentViewController(activityVC, animated: true, completion: nil)

答案 1 :(得分:0)

如果您想通过facebook分享您的文字,请添加excludeActivities

let activityVC = UIActivityViewController(activityItems: objects2Share, applicationActivities: nil)

let excludeActivities = [UIActivityTypePostToFacebook, UIActivityTypePostToTwitter, UIActivityTypeMessage, UIActivityTypeMail]

activityVC.excludedActivityTypes = excludeActivities  
self.presentViewController(activityVC, animated: true, completion: nil)