5
votes

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!

3
Are you logged in with a user to one of the social networks?LoVo
Thanks for the suggestion, I'm logged into the facebook app, but on safari the facebook share option is still available, there is also an option for twitter even though I don't have twitter installed on my phone.Gmeister4
Here is a tutorial, i hope it helps: codingexplorer.com/sharing-swift-app-uiactivityviewcontrollerLoVo
Thanks but ive already looked through that tutorial (and many more!) but that guy seems to just copy in very similar code to mine in his project, and it just works. Could it be something to do with my developer license at all?Gmeister4
Also interestingly, I set it to cancel "Add to the reading list": UIActivityTypeAddToReadingList but it still appears.. strangeGmeister4

3 Answers

1
votes

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

0
votes

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

0
votes

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