Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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://stackoverflow.com/questions/28169192/ios-swift-uiactivityviewcontroller-completion-handler-returns-success-when-tweet

And this sample project:

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

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

like image 713
Gmeister4 Avatar asked Nov 10 '22 17:11

Gmeister4


1 Answers

In the comments of dvdowns.com/uiactivityviewcontroller/ you have the answer:

let secondActivityItem : NSURL = NSURL(fileURLWithPath:...

NSURL(fileURLWithPath: "http://www.website.com/")! (bad)

NSURL(string: “http://www.dvdowns.com/”)! (good)

Regards!!

like image 168
Misael Avatar answered Nov 14 '22 23:11

Misael