iOS-Facebook SDK-SSO-不带登录对话框登录

iOS-Facebook SDK-SSO-不带登录对话框登录,ios,iphone,facebook-login,facebook-sdk-3.1,Ios,Iphone,Facebook Login,Facebook Sdk 3.1,我在运行时通过以下方式更改Info.plist文件: -(void) setBundleUrlScheme:(NSString*)fbAppId { NSString *path= [[NSBundle mainBundle] pathForResource:@"Info" ofType:@"plist"]; if(path){ NSMutableDictionary *dict = [[NSMutableDictionary alloc] initWithC

我在运行时通过以下方式更改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];

}
}

然后,我尝试在没有登录对话框的情况下登录facebook(我的应用程序允许SSO):

每次我在allowLoginUI中通过
NO
openActiveSessionWithReadPermissions
返回
NO
,成功/失败块永远不会运行

没有登录界面,我如何登录facebook


提前感谢。

代码的第一部分将无法工作,无法写入mainBundle,因为它在设备上是只读的

秒部分可能会失败,因为代码的第一部分失败

如果文件实际写入,只需在代码中添加此检查:

// write back to file
if (![dict writeToFile:path atomically:YES]) {
   NSLog:(@"Failed to write: %@", path);
}

但我看到Info.plist实际上发生了变化。为什么会这样?@gran33你是在模拟器里测试的吗?因为在真实设备上,您无法写入主捆绑包。是的,在真实设备上。我在这行写:[dict writeToFile:path原子:YES];在真正的设备上不可能,mainBundle是只读的,不能写入。除非你的设备被越狱。根据你的回答,我如何使用不同于Info.plist中的FacebookAppID登录Facebook?
// write back to file
if (![dict writeToFile:path atomically:YES]) {
   NSLog:(@"Failed to write: %@", path);
}