调用presentShareDialogWithParams时,共享对话框中没有内容:clientState:handler

时间:2014-07-24 00:31:04

标签: ios xcode facebook ios7 share

我已经按照Facebook的指南找到here,用于在iOS应用中共享链接,但是当在Facebook应用中打开共享对话框时,没有链接,预览或图片。这就是我所看到的:

enter image description here

如果我在那里输入评论,我可以发帖,但只有评论在帖子中可见,而不是我评论的内容。在我的评论之上它说“2小时前通过...”和我的应用程序的名称。

我当然创建了一个facbook应用程序,它是“实时”(不是在开发模式下)。我也在[FBSettings setDefaultAppID:];中呼叫[FBAppEvents activateApp];applicationDidBecomeActive

这是我的代码:

NSString *name = @"Name here";
NSString *url = @"https://google.com/";
NSString *url = @"Caption here";
NSString *linkDescription = @"Description here";
NSString *imageUrl = @"http://i.imgur.com/zLS0g9Z.jpg";

//*

// Check if the Facebook app is installed and we can present the share dialog
FBLinkShareParams *params = [[FBLinkShareParams alloc] init];
params.link = [NSURL URLWithString:url];
params.name = name;
params.caption = caption;
params.linkDescription = linkDescription;
params.picture = [NSURL URLWithString:imageUrl];

// If the Facebook app is installed and we can present the share dialog
if ([FBDialogs canPresentShareDialogWithParams:params]) {
    // Present the share dialog
    [FBDialogs presentShareDialogWithParams:params clientState:nil handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
        if(error) {
            // An error occurred, we need to handle the error
            // See: https://developers.facebook.com/docs/ios/errors
            NSLog(@"Error publishing story: %@", error.description);
        } else {
            // Success
            //NSLog(@"result %@", results);
        }
    }];

} else {
    // Fallback: Present the feed dialog
}

当我尝试分享Open Graph故事(here)时也会发生同样的事情。

1 个答案:

答案 0 :(得分:0)

我明白了。我的网址包含一些特殊字符(我在代码中用https://google.com/替换了我的代码中的实际网址,然后在此处发布代码)。只需添加以下行:

url = [url stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]

解决了我的问题:)