我正在尝试在 Facebook 上分享图形对象,但在添加图像时遇到了一些问题。
这是我当前的代码:
// Construct an FBSDKSharePhoto
UIImage* psImg = [UIImage imageNamed:@"fb_share_logo"];
FBSDKSharePhoto *photo = [[FBSDKSharePhoto alloc] init];
photo.image = psImg;
photo.userGenerated = NO;
NSDictionary *properties = @{@"og:type": @"my_obj",
@"og:title": @"Title",
@"og:description": @"Description",
@"og:web": @"http://www.mywebssite.com"
// @"og:image": @[photo]
};
//create GraphObject from properties
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
//create action
FBSDKShareOpenGraphAction *action = [FBSDKShareOpenGraphAction actionWithType:@"my_action" object:object key:@"my_key"];
//create content
FBSDKShareOpenGraphContent *content = [FBSDKShareOpenGraphContent new];
//set content action
content.action = action;
content.previewPropertyName = @"my_prop_type";
FBSDKShareDialog *shareDialog = [[FBSDKShareDialog alloc] init];
shareDialog.fromViewController = self;
shareDialog.shareContent = content;
if (![shareDialog canShow]) {
// update the app UI accordingly
NSLog(@"is showing");
}
NSError *error;
if (![shareDialog validateWithError:&error]) {
// check the error for explanation of invalid content
NSLog(@"error");
}
if([shareDialog canShow]){
[shareDialog show];
}
最佳答案
您的代码中未设置 shareDialog 的模式参数。
所以首先你需要设置如下(more details here):
dialog.mode = FBSDKShareDialogModeNative; // to open native app
if (![dialog canShow]) {
// if there is no FB app installed on that device, use browser
dialog.mode = FBSDKShareDialogModeFeedBrowser;
}
如果您仍然无法打开共享对话框,您应该检查您的 Info.plist 文件中的 LSApplicationQueriesSchemes 键并查看它是否设置如下(developers.facebook):
<key>LSApplicationQueriesSchemes</key>
<array>
<string>fbapi</string>
<string>fbapi20130214</string>
<string>fbapi20130410</string>
<string>fbapi20130702</string>
<string>fbapi20131010</string>
<string>fbapi20131219</string>
<string>fbapi20140410</string>
<string>fbapi20140116</string>
<string>fbapi20150313</string>
<string>fbapi20150629</string>
<string>fbauth</string>
<string>fbauth2</string>
<string>fb-messenger-api20140430</string>
</array>
关于ios - 如果添加图像,Facebook 共享图形对象不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35315010/