I want to share just simple text using UIActivityViewController I am using swift, with xcode 6.3 The code is very simple, work great for photos, but not just text, I don't want to include any web URL with the objectsToShare, just clean text Here is the code:
var objectsToShare: ["some text to share"]!
let activityVC = UIActivityViewController(activityItems: objectsToShare, applicationActivities: nil)
//handler for completed task
activityVC.completionHandler = {(activityType, completed:Bool) in
if !completed {
println("cancelled")
return
}
reportCompleted() //report to server it's done.
}
//Excluded Activities Code
activityVC.excludedActivityTypes = [UIActivityTypeAirDrop, UIActivityTypeAddToReadingList, UIActivityTypeCopyToPasteboard ]
//activate the share view
self.presentViewController(activityVC, animated: true, completion: {
(complete) in
println(complete)
})
Now I know that it's all depends on the user have Facebook - not only on his phone, but also on his setting. (I tried that directly from my phone 6, which has Facebook setting, and not from the simulator) This code once worked fine, and still working good for images, and not text, but from some reason, it stop working for text sharing, Maybe the text itself has something to do with, maybe my code is not good, or maybe Facebook, change something.
Thank you for any thought about the subject.
To make thing more strange I found 2 more strange things.
//code that work:
var myWebsite = NSURL(string: "http://www.someurl.com/")
let textToShare = "Swift is awesome! Check out this website about it!"
objectsToShare = [textToShare , myWebsite!]
//continue regular.
//code that doesn't work:
let textToShare = "Swift is awesome! Check out this website about it!"
objectsToShare = [textToShare ]
It seems that it is not a bug but facebook policy update:
"After discussing this with our team regarding stripping the pre-filling message area of text, this is actually BY DESIGN with the new share extension. Pre-filling texts violates Platform Policy 2.3 ..... So in all enforcing policy 2.3 is a feature and not a bug. " https://developers.facebook.com/bugs/949486035103197/
I read and the problem isn't iOS 8.3, is FacebookApp v29 and they haven't fix it on today update. If you uninstall your FacebookApp it works.
I can´t post images, but if you try this code with Facebook app installed and without it you will see the difference
func didPressShare(sender: AnyObject) {
if SLComposeViewController.isAvailableForServiceType(SLServiceTypeFacebook){
var facebookSheet:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
facebookSheet.setInitialText("This is without facebook on device")
self.presentViewController(facebookSheet, animated: true, completion: nil)
} else {
var alert = UIAlertController(title: "Accounts", message: "Please login to a Facebook account to share.", preferredStyle: UIAlertControllerStyle.Alert)
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler: nil))
self.presentViewController(alert, animated: true, completion: nil)
}
}
As they said: "Sorry for the delay everyone but we have this fix scheduled for v31. The reason for the delay is the cycle for getting updates approved for the App Store takes time. We appreciate your patience."
https://developers.facebook.com/bugs/949486035103197/
They say it will be fixed on next update.
I just tested on my example, using this code:
@IBAction func shareMoment_Action(sender: AnyObject) {
let firstActivityItem = "This is a simple text"
var activityVC = UIActivityViewController(activityItems: [firstActivityItem], applicationActivities: nil)
activityVC.excludedActivityTypes = [
UIActivityTypePostToWeibo,
UIActivityTypePrint,
UIActivityTypeCopyToPasteboard,
UIActivityTypeAssignToContact,
UIActivityTypeSaveToCameraRoll,
UIActivityTypeAddToReadingList,
UIActivityTypePostToFlickr,
UIActivityTypePostToVimeo,
UIActivityTypePostToTencentWeibo,
UIActivityTypeAirDrop
]
activityVC.completionWithItemsHandler = {(activityType: String!, completed: Bool, arrayOptions: [AnyObject]!, error: NSError!) in
println(activityType)
}
self.presentViewController(activityVC, animated: true, completion: nil)
}
And share is working fine for every option selected!
It is working well on my side. Please check your code again!
I have been facing the same problem but have not been able to fix it. This is what I found out so far:
It's hard to tell if Facebook actually has something to do with this bug, as they have a policy of entering bogus release notes for updates.
Since the sharing feature is not a main feature in my app, I will wait until the release of iOS8.4 and/or Facebook.app v30.0
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With