gpt4 book ai didi

ios - FBSession requestNewPublishPermissions如何处理 "Skip"用户操作

转载 作者:技术小花猫 更新时间:2023-10-29 10:51:10 25 4
gpt4 key购买 nike

我发现了一个有趣的问题。

当我请求新的发布权限时,fb sdk 会显示带有“跳过”按钮的对话框。我是这样处理的


[[[appDelegate facebook] session] requestNewPublishPermissions:permissions
defaultAudience:FBSessionDefaultAudienceEveryone
completionHandler:^(FBSession *session, NSError *error)
{
if (!error)
{
//do smth if there is no error
}
}];

但是当用户在对话框中按下“跳过”时 - 错误为零。

如何处理?也许我不明白……谢谢。

最佳答案

我也一样,这似乎是 Facebook SDK 中的错误,但我不确定。我添加了额外检查 session 是否具有新权限。

    - (void)postToFacebookWithMessage:(NSString *)message completionBlock:(void (^)(NSError *))completionBlock
{
NSArray *permissions = @[@"publish_actions"];

void (^completionHandler)(FBSession *session, NSError *error) = ^(FBSession *session, NSError *error) {
if (error != nil)
{
if (completionBlock != nil)
{
completionBlock(error);
}
}
else if(![self activeSessionHasPermissions:permissions])
{
NSError *error = [NSError errorWithDomain:@"Facebook" code:FBAccessDisabledCode userInfo:@{NSLocalizedDescriptionKey:NSLocalizedString(@"Facebook access disabled", @"Facebook access disabled")}];
if (completionBlock != nil)
{
completionBlock(error);
}
}
else
{
NSMutableDictionary<FBGraphObject> *action = [FBGraphObject graphObject];
action[@"message"] = message;

[FBRequestConnection startForPostWithGraphPath:@"me/og.posts" graphObject:action completionHandler:^(FBRequestConnection *connection, id result, NSError *error) {
// internal error 1611231 means that this was already posted
if (error.code == 5)
{
error = [NSError errorWithDomain:@"Facebook" code:FBDuplicateActionErrorCode userInfo:@{NSLocalizedDescriptionKey:NSLocalizedString(@"Already posted to Facebook", @"Already posted to Facebook")}];
}

if (completionBlock != nil)
{
completionBlock(error);
}
}];
}
};

if ([self activeSessionHasPermissions:permissions])
{
completionHandler([FBSession activeSession], nil);
}
else
{
[[FBSession activeSession] requestNewPublishPermissions:permissions defaultAudience:FBSessionDefaultAudienceEveryone completionHandler:completionHandler];
}
}

- (BOOL)activeSessionHasPermissions:(NSArray *)permissions
{
__block BOOL hasPermissions = YES;
for (NSString *permission in permissions)
{
NSInteger index = [[FBSession activeSession].permissions indexOfObjectPassingTest:^BOOL(id obj, NSUInteger idx, BOOL *stop) {
if ([obj isEqualToString:permission])
{
*stop = YES;
}
return *stop;
}];

if (index == NSNotFound)
{
hasPermissions = NO;
}
}
return hasPermissions;
}

希望对你有帮助

关于ios - FBSession requestNewPublishPermissions如何处理 "Skip"用户操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16571476/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com