简体   繁体   中英

Facebook sharing issue for a Link and a screenshot

When I only share a link, the link appears. When I only share an image, the image appears. However, when I want to do both with the code below, only the link appears, without the image.

Can I do both?

let screen = UIScreen.mainScreen()

    if let window = UIApplication.sharedApplication().keyWindow {
        UIGraphicsBeginImageContextWithOptions(screen.bounds.size, false, 0);
        window.drawViewHierarchyInRect(window.bounds, afterScreenUpdates: false)
        let image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();

        let composeSheet = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
        let urlPath: String = "https://itunes.apple.com/us/app/reflex-test!-how-far-can-you/id1123340346?ls=1&mt=8"
        let url: NSURL = NSURL(string: urlPath)!
        composeSheet.addURL(url)
        composeSheet.addImage(image)

        presentViewController(composeSheet, animated: true, completion: nil)

        }
    }   
}

You can only do things with the Facebook API, that you can do on the Facebook website.

You can't share a link and an image at the same time on the Facebook website.

That means, you can't do that with the API either.

But, you could add the link as the text of the post.

I am using the same code and it is working for me. Please find attached screenshots below:

在此处输入图片说明

在此处输入图片说明

在此处输入图片说明

I am using the following code:

let facebookSheet:SLComposeViewController = SLComposeViewController(forServiceType: SLServiceTypeFacebook)
            UIGraphicsBeginImageContextWithOptions(UIScreen.mainScreen().bounds.size, false, 0);
            UIApplication.sharedApplication().keyWindow!.drawViewHierarchyInRect(UIApplication.sharedApplication().keyWindow!.bounds, afterScreenUpdates: false)
            let image = UIGraphicsGetImageFromCurrentImageContext();
            UIGraphicsEndImageContext();
            facebookSheet.addImage(image)
            facebookSheet.addURL(NSURL(string: "http://www.google.co.in"))
            self.presentViewController(facebookSheet, animated: true, completion: nil)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM