尝试从Facebook上的应用程序共享图像时,应用程序崩溃

时间:2014-04-08 09:03:12

标签: ios facebook ios7 unrecognized-selector facebook-sdk-3.1

我正在尝试将我的应用程序中的帖子分享到Facebook。当我在'picture'键中输入图像链接时它工作正常,但是当我给自己的一张照片分享时应用程序崩溃了。这是我正在使用的代码

NSMutableDictionary *params = [NSMutableDictionary dictionaryWithObjectsAndKeys:@"Magic Photo from Abracadabra Snap!", @"name",@"Edit photos, move objects around,remove photo bombs", @"caption",@"Use  automatic object detector to select objects or make your own custom selection.Remove the unwanted objects or photobomb,or move objects around.Do crazy stuff with your pictures , save and share with friends.", @"description",@"http://www.arkhitech.com/abracadabra/", @"link",tempImageForFacebookShare, @"picture",nil];

// Show the feed dialog
[FBWebDialogs presentFeedDialogModallyWithSession:nil parameters:params handler:^(FBWebDialogResult result, NSURL *resultURL, NSError *error)
{
            if (error)
                {
                // An error occurred, we need to handle the error
                // See: https://developers.facebook.com/docs/ios/errors
                NSLog([NSString stringWithFormat:@"Error publishing story: %@", error.description]);
                }
            else {

                if (result == FBWebDialogResultDialogNotCompleted)
                {
                    // User cancelled.
                    NSLog(@"User cancelled.");
                }
            else
            {
                // Handle the publish feed callback
                NSDictionary *urlParams = [self parseURLParams:[resultURL query]];

            if (![urlParams valueForKey:@"post_id"])
                {
                // User cancelled.
                NSLog(@"User cancelled.");

                }
            else
                {
                // User clicked the Share button
                NSString *result = [NSString stringWithFormat: @"Posted story, id: %@", [urlParams valueForKey:@"post_id"]];
                NSLog(@"result %@", result);
                }
          }
        }
}];

图像为10 * 10图像,错误为Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIImage length]: unrecognized selector sent to instance 0xab7b900'。请指导一下这个问题

2 个答案:

答案 0 :(得分:1)

它不适用于UIImage,因为Api只允许string s:

  

picture:确定与链接关联的预览图像。的字符串

来源:Graph API Reference

picture参数是链接的预览图片,无法上传。

答案 1 :(得分:-1)

您的代码看起来有效,但是您向Facebook发送了UIImage,其中NSArray的{​​{1}}内容为UIImages

请按以下方式更改您的NSDictionary代码:

@[tempImageForFacebookShare], @"picture",

看看它是否解决了问题。