Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SLComposeViewController post both image and url ios9

What I am trying to do and it doesn't work is the following: post an image of my choise and also an url to facebook using the built in facebook sharer, the problem is that it doesn't work to upload both, it's either picture + text and works nice or url + text and works nice, but when I combine them text+picture+url it gets the picture from the url and not my uploaded pic. Any suggestions? I am doing this on iOS9

    UIImage *tableViewScreenshot = [tblFeed screenshotOfCellAtIndexPath:idx];

    SLComposeViewController *fbSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
    [fbSheet setInitialText:@"I need your vote"];
    [fbSheet addURL:[NSURL URLWithString:str]];
    [fbSheet addImage:tableViewScreenshot];
like image 792
Catalin Avatar asked Oct 17 '15 21:10

Catalin


1 Answers

The problem is that Facebook has changed some policies and by this you can't have a text or an image present as a default. That's why you're not seeing the text and photo. Here are 2 scenarios one with Facebook app installed and another one without Facebook app installed. The below one is when the Facebook app is already installed on the device. enter image description here

And this one is when the Facebook app is not installed on the device

enter image description here

And this is my code:

 SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];

[controller addURL:[NSURL URLWithString:@"https://www.google.com"]];
[controller addImage:[UIImage imageNamed:@"icon_circle"]];
[controller setInitialText:@"Bhavuk you're great!"];

[self presentViewController:controller animated:YES completion:nil];

So If you want to share everything, better use FB SDK.

like image 83
Bhavuk Jain Avatar answered Oct 10 '22 22:10

Bhavuk Jain