samedi 28 mars 2015

iOS 8.1 Swift UIActivityViewController does not show social media share (Facebook, twitter, WhatsApp etc)

I'm trying to link sharing functionality into my swift app but am having a problem. I'm using UIActivityViewController to share an image and text, but the only options available are these:


Share options


I would like the options for Facebook, Twitter and Whatsapp (and the rest!) but I can't figure out what I'm doing wrong.


I have also tried other code/ source projects but I'm having the same problem, however if I go on safari on the device it does offer the missing social media options on the share sheet.


Here is my code:



func shareTextImageAndURL(#sharingText: String?, sharingImage: UIImage?, sharingURL: NSURL?) {
var sharingItems = [AnyObject]()

if let text = sharingText {
sharingItems.append(text)
}
if let image = sharingImage {
sharingItems.append(image)
}
if let url = sharingURL {
sharingItems.append(url)
}

let activityViewController = UIActivityViewController(activityItems: sharingItems, applicationActivities: nil)

activityViewController.excludedActivityTypes = [UIActivityTypeAirDrop, UIActivityTypeAddToReadingList]


if(activityViewController.popoverPresentationController != nil) {
activityViewController.popoverPresentationController?.sourceView = self.view;
var frame = UIScreen.mainScreen().bounds
// frame.height = frame.height / 2
var newFrame = CGRect(x: frame.origin.x, y: frame.origin.y, width: frame.width, height: frame.height / 2)
activityViewController.popoverPresentationController?.sourceRect = frame;
}

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


Calling the method with:



var image = UIImage(named: "icon_messages.png")?

shareTextImageAndURL(sharingText: "Hello this is a test", sharingImage: image, sharingURL: NSURL(string: "http://www.example.com/"))


My device is an iPhone 4s running iOS 8.1.


Here is the other code I tried (to the same effect:)



http://ift.tt/1tk3QWD


And this sample project:



ttp://www.dvdowns.com/uiactivityviewcontroller/


Does anyone have ANY idea what could be going on here? Thanks in advance!


Aucun commentaire:

Enregistrer un commentaire