Error when using [FBSession openActiveSessionWithPublishPermissions: ..]

后端 未结 4 793
轮回少年
轮回少年 2020-12-14 13:30

I\'m updating an app to use the latest Facebook SDK in order to gain access to the iOS6 native Facebook support. It currently uses a pretty old version of the Facebook SDK.

4条回答
  •  渐次进展
    2020-12-14 14:30

    Based on everything I've read on Facebook's Developer sites (which is somewhat contradictory) the workflow of a "publish only" app is not something to which they've given much thought, and Apple/iOS seems to have disregarded altogether.

    Facebook provides some guidance in the docs you referenced:

    Tip 5: Disabling the native Login Dialog

    In some cases, apps may choose to disable the native Login Dialog to use new versions of the Facebook SDK but to avoid rewriting the ways they request permissions from users. To use the previous behavior of fast-app-switch for login, use the deprecated FBSession methods openActiveSessionWithPermissions and reauthorizeWithPermissions.

    This is the route I am currently following. Slightly different, but same general effect.

    if (FBSession.activeSession.isOpen  == NO) {
        // This will bypass the ios6 integration since it does not allow for a session to be opened
        // with publish only permissions!
        FBSession* sess = [[FBSession alloc] initWithPermissions:[NSArray arrayWithObject:@"publish_actions"]];
        [FBSession setActiveSession:sess];
        [sess openWithBehavior:(FBSessionLoginBehaviorWithFallbackToWebView) completionHandler:^(FBSession *session, FBSessionState status, NSError *error) {
            [self onSessionStateChange:session
                              andState:status
                              andError:error];
        }];
    

    The upshot is, the app will always bypass the IOS6 integration for signing on for publish, and in most cases (since users typically will already have Facebook installed on the phone) switchover to the Facebook app for a single auth approval.

    If the user elects to sign-on to our app using their Facebook account, I call openActiveSessionWithReadPermissions, which will use the IOS6 Facebook integration if present. If they subsequently decide to share, I then call reauthorizeWithPublishPermissions which will also use the IOS6 integration if available.

    Given the minimal and confusing documentation available I cannot be sure if this is the "right" way to approach this, but it seems to work. You can use the same code for an IOS5 or IOS6 app since it only makes calls through the Facebook SDK. It also honors the not mixing read/publish permissions in the same request Facebook is now promoting.

提交回复
热议问题