0

I'm developing an iOS application using swift and firebase.

I'm trying to add sharing ability, where the user can share some information from firebase to social networkings apps.

Here's the button I added:

     @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)
}

When I tried it, it worked for all social networks apps except for whatsapp and Facebook!

*Here's the error I got when I try to share it to whatsapp: enter image description here

*Here's What I got when I share to Facebook: enter image description here And the link is empty!

Is there anybody know how can I solve this? And why this happens?

Mariah
  • 573
  • 3
  • 10
  • 26

2 Answers2

1

It's a bug on whatsapp.

Check this thread. It discusses the same. It seems like a very recent bug as earlier the same methods used to work. Check this answer by santhu for possible workaround or wait since they have admitted to resolve the bug.

if you try this code, you can share just the URL which I was talking about.

    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)
Community
  • 1
  • 1
Umar Farooque
  • 2,049
  • 21
  • 32
0

if you want to share your text via facebook add excludeActivities

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

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

activityVC.excludedActivityTypes = excludeActivities  
self.presentViewController(activityVC, animated: true, completion: nil)
Sahil
  • 9,096
  • 3
  • 25
  • 29
shalu tyagi
  • 148
  • 8