gpt4 book ai didi

ios - Facebook iOS SDK 不调用完成处理程序

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:10:47 24 4
gpt4 key购买 nike

问题:

使用 FB SDK 和 openActiveSessionWithReadPermissions 方法,当应用程序从 Facebook 网络或 Facebook 应用程序重新打开时,完成处理程序似乎没有被调用,我收到此错误输出:

FBSDKLog:FBSession 无效 从 FBSessionStateCreated 到 FBSessionStateClosed 的转换FBSDKLog:FBSession从FBSessionStateCreated到FBSessionStateCreatedOpening的转换

上下文

  • 使用 Facebook SDK 3.2.1
  • 应用专为 iOS 5.0+ 构建
  • 使用 xCode 4.6.1
  • 在模拟器 iOS 5.1 上测试
  • 在运行 iOS 6.1.2 的 iPhone 4S 上进行测试(不使用 6.0 社交框架,因为想测试 5.0+ 的实现)
  • 更新最初为 iOS 3.0 构建并使用旧版本的 sharekit 的应用程序,但现在已针对 ARC 进行了更新,我相信共享工具包的实现都已被注释掉 - 希望问题不会与旧的共享工具包功能,在代码中找不到任何内容

采取的解决措施

搜索整个Stack Overflow,发现提到类似问题但没有解决方案

细节:

这些是我在应用程序中实现 Facebook 连接所采取的步骤。

代码中的高级步骤:

  • 我在 AppDelegate 中设置了我的 FB 方法
  • 在特定的 View Controller 中,我有一个按钮调用 openSessionWithAllowLoginUI 方法来启动登录过程

代码

AppDelegate.m

- (void)applicationDidFinishLaunching:(UIApplication *)application 
{
// set up facebook logging
[FBSettings setLoggingBehavior:[NSSet setWithObjects:FBLoggingBehaviorFBRequests, FBLoggingBehaviorFBURLConnections, FBLoggingBehaviorAccessTokens, FBLoggingBehaviorSessionStateTransitions, nil]];

// Call the ACAccountStore method renewCredentialsForAccount, which will update the OS's understanding of the token state
ACAccountStore *accountStore;
ACAccountType *accountTypeFB;
if ((accountStore = [[ACAccountStore alloc] init]) &&
(accountTypeFB = [accountStore accountTypeWithAccountTypeIdentifier:ACAccountTypeIdentifierFacebook] ) ){

NSArray *fbAccounts = [accountStore accountsWithAccountType:accountTypeFB];
id account;
if (fbAccounts && [fbAccounts count] > 0 &&
(account = [fbAccounts objectAtIndex:0])){

[accountStore renewCredentialsForAccount:account completion:^(ACAccountCredentialRenewResult renewResult, NSError *error) {
//we don't actually need to inspect renewResult or error.
if (error){

}
}];
}
}

- (void)applicationDidBecomeActive:(UIApplication *)application
{
// We need to properly handle activation of the application with regards to Facebook Login
// (e.g., returning from iOS 6.0 Login Dialog or from fast app switching).
NSLog(@"Calling app did become active");
[FBSession.activeSession handleDidBecomeActive];
}

/*
* Callback for session changes.
*/
- (void)sessionStateChanged:(FBSession *)session
state:(FBSessionState) state
error:(NSError *)error
{
NSLog(@"Session State Changed");

switch (state) {
case FBSessionStateOpen:
if (!error) {
// We have a valid session
NSLog(@"User session found");
}
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed:
[FBSession.activeSession closeAndClearTokenInformation];
break;
default:
break;
}

[[NSNotificationCenter defaultCenter]
postNotificationName:FBSessionStateChangedNotification
object:session];

if (error) {
UIAlertView *alertView = [[UIAlertView alloc]
initWithTitle:@"Error"
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[alertView show];
}
}

/*
* Opens a Facebook session and optionally shows the login UX.
*/
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI {
NSLog(@"Openning session with Facebook");
return [FBSession openActiveSessionWithReadPermissions:nil
allowLoginUI:allowLoginUI
completionHandler:^(FBSession *session,
FBSessionState state,
NSError *error) {
[self sessionStateChanged:session
state:state
error:error];
}];
}


/*
* If we have a valid session at the time of openURL call, we handle
* Facebook transitions by passing the url argument to handleOpenURL
*/
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation {
// attempt to extract a token from the url
NSLog(@"Calling open URL");
return [FBSession.activeSession handleOpenURL:url];
}

- (void) closeSession {
NSLog(@"Clossing Facebook Sessions");
[FBSession.activeSession closeAndClearTokenInformation];
}

- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
NSLog(@"handleOpenUrl Called");
return [FBSession.activeSession handleOpenURL:url];

}

带按钮的 View Controller

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.

// Register for Facebook change notification
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(sessionStateChanged:)
name:FBSessionStateChangedNotification
object:nil];
}

- (IBAction)login:(id)sender {
ATIAppDelegate *myAppDelegate = (ATIAppDelegate *)[[UIApplication sharedApplication]delegate];
[myAppDelegate openSessionWithAllowLoginUI:YES];
}

我认为问题可能是什么?

  • 好像是跟 token 有关的东西?
  • 或者可能是通知中心?
  • 请注意,在测试期间,我一直在撤销 Facebook 应用程序对我帐户的访问权限,然后尝试再次登录该应用程序,我发现这些已导致其他用户出现问题<

最佳答案

好吧,我想通了 - 这个问题与 FB 本身无关,应用程序(我正在更新别人的代码)在 .plist 中有一个设置 - '应用程序不在后台运行'设置为是的。

这意味着一旦应用程序从 Facebook 应用程序或 Facebook 移动网站重新启动,它就没有准备好处理下一步。

enter image description here

关于ios - Facebook iOS SDK 不调用完成处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15775160/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com