Reputation: 3506
I am using the following code to post photo on facebook.
if ([FBDialogs canPresentShareDialogWithPhotos])
{
FBShareDialogPhotoParams *params = [[FBShareDialogPhotoParams alloc] init];
// Note that params.photos can be an array of images. In this example
// we only use a single image, wrapped in an array.
params.photos = @[imageDetails.chosenImage];
params.place=@"Abracadabra Snap! ios application";
[FBDialogs presentShareDialogWithPhotoParams:params
clientState:nil
handler:^(FBAppCall *call,
NSDictionary *results,
NSError *error) {
if (error) {
NSLog(@"Error: %@",
error.description);
} else {
NSLog(@"Success!");
}
}];
}
It shows me a dialog where I write some text and click on post, and after I click post, it uploads the image and comes back to the calling controllers, but does not return either error or success and doesn't post the image on facebook either. Please help about this problem
Upvotes: 0
Views: 840
Reputation: 319
Add the following code to your appdelegate, this ensures that the facebook app can send data back to your app. (taken from: https://developers.facebook.com/docs/ios/share)
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
BOOL urlWasHandled = [FBAppCall handleOpenURL:url
sourceApplication:sourceApplication
fallbackHandler:^(FBAppCall *call) {
NSLog(@"Unhandled deep link: %@", url);
// Here goes the code to handle the links
// Use the links to show a relevant view of your app to the user
}];
return urlWasHandled;
}
Upvotes: 0
Reputation: 747
TRY THIS ...in Share Button......
- (IBAction)facebookPost:(id)sender
{
if ([SLComposeViewController isAvailableForServiceType:SLServiceTypeFacebook])
{
SLComposeViewController *mySLComposerSheet = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
[mySLComposerSheet setInitialText:@"ABC"];
[mySLComposerSheet addImage:[UIImage imageNamed:@"abc.png"]];
[mySLComposerSheet addURL:[NSURL URLWithString:@"google.com"]];
[mySLComposerSheet setCompletionHandler:^(SLComposeViewControllerResult result)
{
switch (result)
{
case SLComposeViewControllerResultCancelled:
{
NSLog(@"Post Canceled");
break;
}
case SLComposeViewControllerResultDone:
{
NSLog(@"Post Sucessful");
break;
}
default:
break;
}
}];
[self presentViewController:mySLComposerSheet animated:YES completion:nil];
}
}
Upvotes: 2