Domanda

I change the Info.plist file in runtime by:

-(void) setBundleUrlScheme:(NSString*)fbAppId {

    NSString *path= [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"];

    if(path){
        NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithContentsOfFile:path];
        NSMutableArray* bundleUrlTypesArray = [dict objectForKey:@"CFBundleURLTypes"];
        NSMutableDictionary* bundleURLSchemes = [bundleUrlTypesArray objectAtIndex:0];

        // set wanted fb app id to plist CFBundleURLSchemes
        [bundleURLSchemes setObject:[NSArray arrayWithObject:[NSString stringWithFormat:@"fb%@", fbAppId]] forKey:@"CFBundleURLSchemes"];

        // write back to file
        [dict writeToFile:path atomically:YES];

}

}

And after that, I try login to facebook without login dialog (my application allow SSO):

[FBSession openActiveSessionWithReadPermissions:@[@"basic_info"]
                                   allowLoginUI:NO
                                 pletionHandler:^(FBSession *session, FBSessionState state, NSError *error) {

            // error occured
            if(error || state == FBSessionStateClosedLoginFailed) {
                NSLog(@"ERROR:%@", error);
            }

            // session opened succefully, run query
            else if (state == FBSessionStateOpen){

                NSLog(@"state:%d", state);
                NSLog(@"I LOGGED IN!");

                sucessBlock();
            }
        }];

Every time i pass NO in allowLoginUI, openActiveSessionWithReadPermissions returns NO and success/failure blocks never running.

How can I login to facebook without login UI?

Thanks in advance.

È stato utile?

Soluzione

The first part of your code will not work, writing to the mainBundle is not possible since it is readonly on the device.

The seconds part may fail because the first part of your code is failing.

Just add this check in your code if the file is actually written:

// write back to file
if (![dict writeToFile:path atomically:YES]) {
   NSLog:(@"Failed to write: %@", path);
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top