简体   繁体   English

iOS-Facebook SDK-SSO-无需登录对话框即可登录

[英]iOS - Facebook SDK - SSO - Login without login dialog

I change the Info.plist file in runtime by: 我通过以下方式在运行时更改Info.plist文件:

-(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): 之后,我尝试登录到没有登录对话框的Facebook(我的应用程序允许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. 每次我在allowLoginUI中传递NO ,openActiveSessionWithReadPermissions openActiveSessionWithReadPermissions返回NO并且成功/失败块永远不会运行。

How can I login to facebook without login UI? 如何在没有登录界面的情况下登录Facebook?

Thanks in advance. 提前致谢。

The first part of your code will not work, writing to the mainBundle is not possible since it is readonly on the device. 您的代码的第一部分将不起作用,无法写入mainBundle,因为它在设备上是只读的。

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM