Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

New Facebook SDK FBSession sessionOpenWithPermissions

I've been trying to develop iOS app using Facebook and I'm new. So I've been trying to make

a login with Facebook, followed a tutorial on Facebook and try to implement it.

But I've encountered, [FBSession sessionOpenWithPermissions] not found. When I run the

app, it will force close and say that error. When build the project, it will show warning

yellow exclamation that sessionOpenWithPermission is not found in FBSession

The tutorial outdated? If it is, then what is the new code for the new Facebook SDK for

sessionOpenWithPermission ?

like image 956
user1383655 Avatar asked Aug 09 '12 05:08

user1383655


People also ask

Which SDKs should I update to implement the new Facebook login?

To implement this new version of Facebook Login, Developers should update their Facebook iOS SDK or Facebook SDK for Unity to version 9.0+. Today, we will launch Facebook Platform SDK version 9.0 and begin the deprecation of all prior SDK versions.

When will the Facebook Platform SDK be deprecated?

The deprecation will happen over a two year period (ending on January 19th, 2023) at the end of which all previous versions of the Facebook Platform SDK will be permanently sunset. At that point, no responses will be generated for any API calls made to previous versions (v8.2 and below) of the Facebook Platform SDK.

How to add Facebook-JS-SDK to tsconfig?

Add the type definitions from @types/facebook-js-sdk with the following npm command: 2. Then add "facebook-js-sdk" to the "types" array in your tsconfig.app.json file:

What is Facebook login’s limited login mode?

Facebook Login now offers a Limited Login mode. When using the limited version of Facebook Login, the fact that a person used Facebook Login with this iOS app will not be used to personalize or measure advertising effectiveness.


2 Answers

Try This Code

 account = [[ACAccountStore alloc] init];
    accountType = [account accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierTwitter];
    arrayOfAccounts = [account accountsWithAccountType:accountType]; 


    appDelegate= (AppDelegate *)[[UIApplication sharedApplication] delegate];
    chk=appDelegate.chk_login;

    if (!appDelegate.session.isOpen) {
        // create a fresh session object
        appDelegate.session = [[FBSession alloc] init];
        if (appDelegate.session.state == FBSessionStateCreatedTokenLoaded) {
            // even though we had a cached token, we need to login to make the session usable
            [appDelegate.session openWithCompletionHandler:^(FBSession *session,
                                                             FBSessionState status,
                                                             NSError *error) {
                // we recurse here, in order to update buttons and labels

            }];
        }
    }
like image 169
Vizllx Avatar answered Oct 05 '22 23:10

Vizllx


Maybe this code helps you, put it in your AppDelegate.m class

- (void)sessionStateChanged:(FBSession *)session
                      state:(FBSessionState) state
                      error:(NSError *)error
{
    switch (state) {
        case FBSessionStateOpen: {
            self.loggedinVCController = [[LoggedinVC alloc] initWithNibName:@"LoggedinVC" bundle:nil];
            self.navController = [[UINavigationController alloc]initWithRootViewController:self.loggedinVCController];
            self.window.rootViewControlle`enter code here`r = self.navController;

        }
            break;
        case FBSessionStateClosed:
        case FBSessionStateClosedLoginFailed:
            // Once the user has logged in, we want them to
            // be looking at the root view.
            [self.navController popToRootViewControllerAnimated:NO];

            [FBSession.activeSession closeAndClearTokenInformation];

            self.viewController = [[SampleViewController alloc] initWithNibName:@"SampleViewController" bundle:nil];
            self.window.rootViewController = self.viewController;

            break;
        default:
            break;
    }

    if (error) {
        UIAlertView *alertView = [[UIAlertView alloc]
                                  initWithTitle:@"Error"
                                  message:error.localizedDescription
                                  delegate:nil
                                  cancelButtonTitle:@"OK"
                                  otherButtonTitles:nil];
        [alertView show];
    }
}
- (BOOL)application:(UIApplication *)application
            openURL:(NSURL *)url
  sourceApplication:(NSString *)sourceApplication
         annotation:(id)annotation
{
    return [FBSession.activeSession handleOpenURL:url];
}
- (void)openSession
{
    [FBSession openActiveSessionWithReadPermissions:nil
                                       allowLoginUI:YES
                                  completionHandler:
     ^(FBSession *session,
       FBSessionState state, NSError *error) {
         [self sessionStateChanged:session state:state error:error];
     }];
}
like image 35
sandy Avatar answered Oct 05 '22 23:10

sandy