Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift UIActivityViewController Image&Url Share not working with FB

I am using UIActivityViewController to share image. After the Facebook recent changes . I am able share an image and Url individualy but i am unable to share both image and url at a time. The same code works fine with Mail, twitter etc., Not sure what i am missing for Facebook.

func shareImage() {
    var myWebsite = NSURL(string:"http://www.google.com/")
    var img: UIImage = currentPhoto!
    var shareItems:Array = [img, myWebsite]
    let activityViewController:UIActivityViewController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
    activityViewController.excludedActivityTypes = [UIActivityTypePrint, UIActivityTypePostToWeibo, UIActivityTypeCopyToPasteboard, UIActivityTypeAddToReadingList, UIActivityTypePostToVimeo]
    self.presentViewController(activityViewController, animated: true, completion: nil)

}
like image 614
Chandu kumar.Alasyam Avatar asked Sep 29 '15 11:09

Chandu kumar.Alasyam


People also ask

What is Uiactivityviewcontroller in Swift?

A view controller that you use to offer standard services from your app.

How is the title of a Uiactivityviewcontroller set?

The title that appears at the top of the the UIActivityItemController is intially simply, "/", with no subtitle, and then after about a second it changes to, "System@snap-2237692", with a subtitle of "File", as per the screenshot below.

What is activity view controller?

The Activity View Controller is a standard view controller that can be used to offer various services from the application. The system provides several standard services, such as copying items to the pasteboard, posting content to social media sites, sending items via email or iMessage, and more.


1 Answers

I have modified your code for swift 2.0:

@IBAction func shareButtonPressed(sender: AnyObject) {

    let myWebsite = NSURL(string:"http://www.google.com/")
    let img: UIImage = image!

    guard let url = myWebsite else {
        print("nothing found")
        return
    }

    let shareItems:Array = [img, url]
    let activityViewController:UIActivityViewController = UIActivityViewController(activityItems: shareItems, applicationActivities: nil)
    activityViewController.excludedActivityTypes = [UIActivityTypePrint, UIActivityTypePostToWeibo, UIActivityTypeCopyToPasteboard, UIActivityTypeAddToReadingList, UIActivityTypePostToVimeo]
    self.presentViewController(activityViewController, animated: true, completion: nil)

}

And it is posting a picture with URL.

Result with this code:

enter image description here

like image 167
Dharmesh Kheni Avatar answered Sep 19 '22 04:09

Dharmesh Kheni