我使用以下代码在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!");
}
}];
}
它显示了一个对话框,我在其中写了一些文字并点击了帖子,点击发布后,它上传图像并返回到调用控制器,但不会返回错误或成功,也不会返回在Facebook上发布图像。请帮忙解决这个问题
答案 0 :(得分:2)
尝试这个......在分享按钮......
- (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];
}
}
答案 1 :(得分:0)
将以下代码添加到您的appdelegate,这可确保Facebook应用可以将数据发送回您的应用。 (摘自: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;
}