Gmeister4
Gmeister4

Reputation: 755

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!

Upvotes: 5

Views: 5433

Answers (3)

lee
lee

Reputation: 8105

I have the same problem, and the answer is:

You're probably not logged in to Facebook or Twitter in the devices Settings. They won't show up here unless the user is logged in. File a bug with Apple.

Thanks Marty. You can find the answer here

Upvotes: 0

Fabio
Fabio

Reputation: 671

From the menu "Share" in iOS 8.3 disappeared Twitter link

Upvotes: 0

Misael
Misael

Reputation: 11

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!!

Upvotes: 1

Related Questions