我正在测试新的 3.1 框架。如果我调用 [FBSession openActiveSessionWithReadPermissions:allowLoginUI:completionHandler
我可以看到 UIAlertView 是如何弹出的(因为我在 ios 中有 facebook 登录)。
但是,如果我自己创建 session 并调用 openWithCompletionHandler
,我将被重定向到 facebook 应用程序或 webview(取决于我是否安装了 facebook 应用程序)。
这是坏了吗?我错过了什么吗?
我不想使用 activeSession 的原因是因为我需要设置 urlSchemeSuffix,而且我在 activeSession 中看不到任何方法(因为这些仅在FBSession 的初始化方法)。
谢谢
最佳答案
查看他们的代码,看起来你需要设置一个特定的行为来让它使用系统帐户(这是来自 FB SDK):
+ (BOOL)openActiveSessionWithPermissions:(NSArray*)permissions
allowLoginUI:(BOOL)allowLoginUI
allowSystemAccount:(BOOL)allowSystemAccount
isRead:(BOOL)isRead
defaultAudience:(FBSessionDefaultAudience)defaultAudience
completionHandler:(FBSessionStateHandler)handler {
// is everything in good order?
[FBSession validateRequestForPermissions:permissions
defaultAudience:defaultAudience
allowSystemAccount:allowSystemAccount
isRead:isRead];
BOOL result = NO;
FBSession *session = [[[FBSession alloc] initWithAppID:nil
permissions:permissions
defaultAudience:defaultAudience
urlSchemeSuffix:nil
tokenCacheStrategy:nil]
autorelease];
if (allowLoginUI || session.state == FBSessionStateCreatedTokenLoaded) {
[FBSession setActiveSession:session];
// we open after the fact, in order to avoid overlapping close
// and open handler calls for blocks
FBSessionLoginBehavior howToBehave = allowSystemAccount ?
FBSessionLoginBehaviorUseSystemAccountIfPresent :
FBSessionLoginBehaviorWithFallbackToWebView;
[session openWithBehavior:howToBehave
completionHandler:handler];
result = session.isOpen;
}
return result;
}
关于IOS Facebook SDK 3.1::使用 fb ios sdk 3.1 登录:只有 openActiveSession 进行应用内登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12608008/