Facebook iOS SDK 3.0 Login Tutorial Issue with FBS

2020-07-18 04:42发布

问题:

I am currently trying to put together an app - with the foundation of it being (hopefully) built on the Facebook iOS SDK 3.0 tutorial.

The tutorial I am following is located at: http://developers.facebook.com/docs/tutorials/ios-sdk-tutorial/authenticate/

I have found there to be a few changes throughout the various SDK versions from Facebook when it comes to the final release.

However I do have one final issue before the code will compile:

"No known class method for selector 'sessionOpenWithPermissions:completionHandler:'"

This error refers to the following code:

- (void)openSession
{
    [FBSession sessionOpenWithPermissions:nil completionHandler:
     ^(FBSession *session, FBSessionState state, NSError *error) {
         [self sessionStateChanged:session state:state error:error];
     }];    
}

When looking at the FBSession.h file in Xcode there is no mention of sessionOpenWithPermissions.

Can anyone please help me with regard to this? I am new to Objective-C/Xcode and am learning via trial by fire.

回答1:

I ran into the same issue, got my code working with the below change.

//REPLACE
[FBSession sessionOpenWithPermissions:nil
                    completionHandler: ^(FBSession *session, FBSessionState state, NSError *error) {
                        [self sessionStateChanged:session state:state error:error];
                    }];

//WITH
[FBSession openActiveSessionWithPermissions:nil
                               allowLoginUI:YES
                          completionHandler:^(FBSession *session, FBSessionState state, NSError *error) {
                              [self sessionStateChanged:session state:state error:error];
                          }];

If you alt click on the method you'll get more info on the parameters to pass. openActiveSessionWithPermissions options



回答2:

It looks like the documentation has a bug. According the API Change log, that class method as been replaced.

FBSession class method sessionOpenWithPermissions:completionHandler: has been removed, instead use the new openActiveSessionWithPermissions:allowLoginUI:completionHandler: class method.

API Change log URL