这样做我有Facebook的共享在我的iOS应用程序工作正常时FB没有安装。并且我已经安装了fb以使用最新的api(4.7.x),现在共享并不起作用。我检查了我是否拥有publish_actions权限(我在调用此方法之前执行了此操作,在开放图形设置,操作类型和功能中检查了'expicitly shared'。我正在验证内容(我没有收到错误)并拥有代表,没有它的方法被调用。
-(void)shareWithFacebook:(NSString *)message
{
if ([[FBSDKAccessToken currentAccessToken] hasGranted:@"publish_actions"])
{
NIDINFO(@"Facebook sharing has publish_actions permission");
}
else
{
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithPublishPermissions:@[@"publish_actions"]
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
NIDERROR(@"Facebook sharing getting publish_actions permission failed: %@", error);
}
];
}
NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithDictionary: @{
@"og:type": @"article",
@"og:title": @"Bloc",
@"og:description": message,
@"og:url": @"http://getonbloc.com/download"
}];
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// Create the action
FBSDKShareOpenGraphAction *action = [FBSDKShareOpenGraphAction actionWithType:@"mynamespace:Share" object:object key:@"article"];
[action setString:@"true" forKey:@"fb:explicitly_shared"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = @"article";
// Share the content
FBSDKShareAPI *shareAPI = [[FBSDKShareAPI alloc] init];
shareAPI.shareContent = content;
shareAPI.delegate = self;
NSError *error;
if([shareAPI validateWithError:&error] == NO)
{
NIDERROR(@"Facebook sharing content failed: %@", error);
}
[shareAPI share];
}
#pragma mark - FBSDKSharingDelegate
- (void) sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NIDINFO(@"Facebook sharing completed: %@", results);
}
- (void) sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
NIDERROR(@"Facebook sharing failed: %@", error);
}
- (void) sharerDidCancel:(id<FBSDKSharing>)sharer
{
NIDINFO(@"Facebook sharing cancelled.");
}
没有ios9问题。 FB最新api(4.7.x)问题 –