gpt4 book ai didi

ios - Facebook 登录在冷启动时崩溃

转载 作者:行者123 更新时间:2023-11-29 12:19:20 24 4
gpt4 key购买 nike

在为我们的应用程序实现新的 Facebook 登录时,我遇到了一些麻烦。我们正在使用 Facebook SDK v4.3 进行开发。登录/注册过程在内存不足的设备上崩溃。我们怀疑低内存限制导致我们的应用程序在触发切换到 Facebook 进行身份验证时终止。作为 Facebook 旧版 SDK 中的文档(链接 https://developers.facebook.com/docs/facebook-login/ios#login-apicalls ):

Login flows require an app switch to complete, it's possible your app gets terminated by iOS in low memory conditions or if your app does not support backgrounding.

In that case, the state change handler supplied to your open call disappears.

To handle that scenario explicitly assign a state change handler block to the FBSession instance any time prior to the handleOpenURL: call:

// During the Facebook login, your app passes control to the Facebook iOS app or Facebook in a mobile browser.
// After authentication, your app will be called back with the session information.
- (BOOL)application:(UIApplication *)application
openURL:(NSURL *)url
sourceApplication:(NSString *)sourceApplication
annotation:(id)annotation
{
// Note this handler block should be the exact same as the handler passed to any open calls.
[FBSession.activeSession setStateChangeHandler:^(FBSession *session, FBSessionState state, NSError *error) {

// Retrieve the app delegate
AppDelegate* appDelegate = [UIApplication sharedApplication].delegate;
// Call the app delegate's sessionStateChanged:state:error method to handle session state changes
[appDelegate sessionStateChanged:session state:state error:error];
}];
return [FBAppCall handleOpenURL:url sourceApplication:sourceApplication];
}

不幸的是,新的 Facebook SDK 弃用了 FBSession.activeSession 及其 stateChangeHandler。我遵循了我的应用程序的自定义 UI FBLogin 按钮,这是我的 appDelegate 代码

-(BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
return [[FBSDKApplicationDelegate sharedInstance] application:application
openURL:url
sourceApplication:sourceApplication
annotation:annotation];
}

代码工作正常,在正常情况下完美执行。但是,它在冷启动时表现异常(由于内存不足)。所以我的问题是:我们如何防止这种情况发生?新 SDK 是否有等效的处理程序?

附言。我完成了管理设备内存的工作。但在这种压力条件下它仍然无法正常工作。

编辑:我只想获取用户成功的基本信息。因此,我不需要跟踪(或不需要)访问 token 。这是我用来调用登录的代码块

    FBSDKLoginManager *login = [[FBSDKLoginManager alloc] init];
[login logInWithReadPermissions:@[@"email"] handler:^(FBSDKLoginManagerLoginResult *result, NSError *error) {
if (error) {
[ErrorMessageDisplay displayErrorAlertOnViewController:self withTitle:FB_LOGIN_ERROR_TITLE andMessage:FB_LOGIN_ERROR_MESSAGE];
[self.loginView enableLoginButtons];
} else if (result.isCancelled) {
[ErrorMessageDisplay displayErrorAlertOnViewController:self withTitle:FB_LOGIN_CANCEL_TITLE andMessage:FB_LOGIN_CANCEL_MESSAGE];
[self.loginView enableLoginButtons];
} else {
[[[FBSDKGraphRequest alloc] initWithGraphPath:@"me" parameters:nil] startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id user, NSError *error) {
//TODO do something in here
}];
}
}];

使用代码的一部分,应用程序在使用 facebook 进行身份验证后仍然卡住在内存不足的情况下。事实上,处理程序根本没有

最佳答案

  1. 确保您遵循 https://developers.facebook.com/docs/ios/getting-started 中的所有步骤包括连接 FBSDKApplicationDelegateapplication:didFinishLaunchingWithOptions:(除了 openURL:)
  2. 在应用程序的适当区域检查 FBSDKAccessToken currentAccessToken(例如 viewDidLoad,如 https://developers.facebook.com/docs/facebook-login/ios/ 中所述)。这将由 SDK 在您的应用“冷启动”的情况下为您设置。

关于ios - Facebook 登录在冷启动时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31082441/

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