ios - FBSDK 4.7.1登录时"You have already authorized yourApp"

标签 ios objective-c facebook ios9 fbsdk

我正在关注 Facebook's own tutorial对于 iOS (Objective-C) 中的 FB 登录,但每次我登录时 - 在初始权限授权屏幕之后 - 我都会收到臭名昭著的“您已经授权此应用程序” WebView 。

我已经阅读了大量的帖子,但我无法将其整理出来,因此(重新)发布。我觉得这很奇怪,因为该应用程序除了样板登录代码外什么都没有。这种行为在模拟器和真实设备中都会发生。

Can't seem to shake this webview out of the way

此应用适用于 iOS 9.0,我使用的是 FBSDK 4.7.1(通过 CocoaPods 安装):

pod 'FBSDKLoginKit', '~> 4.6'

代码本身就是样板文件,这是我的 AppDelegate.m:

#import "AppDelegate.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>

@interface AppDelegate ()

@end

@implementation AppDelegate

- (void)applicationDidBecomeActive:(UIApplication *)application {
    [FBSDKAppEvents activateApp];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    [[FBSDKApplicationDelegate sharedInstance] application:application
                             didFinishLaunchingWithOptions:launchOptions];
    return YES;
}

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

和我的 ViewController.m:

#import "ViewController.h"
#import <FBSDKCoreKit/FBSDKCoreKit.h>
#import <FBSDKLoginKit/FBSDKLoginKit.h>

@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    FBSDKLoginButton *loginButton = [[FBSDKLoginButton alloc] init];
    loginButton.readPermissions = @[@"public_profile", @"email", @"user_friends"];
    [loginButton setLoginBehavior:FBSDKLoginBehaviorSystemAccount]; // No difference

    loginButton.center = self.view.center;
    [self.view addSubview:loginButton];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

以及 Info.plist 的屏幕截图:

Info.plist

最后,我还在控制台中收到了这两个错误:

2015-11-24 11:50:42.855 lixo[26941:389756] -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"
2015-11-24 11:50:42.860 lixo[26941:389756] -canOpenURL: failed for URL: "fbauth2:/" - error: "(null)"

尽管根据我的阅读,如果在 Info.plist 中设置了 LSApplicationQueriesSchemes,则可以安全地忽略它。

有什么办法可以避免这种情况吗?

最佳答案

您可以检查访问 token 的状态,而不是在每次启动时触发登录。如果未过期,则跳过登录,直接开始使用 API。可以使用以下方法检查 token 是否过期:

+(BOOL) accessTokenIsLocalyValid
{
    return [FBSDKAccessToken currentAccessToken] && [[NSDate date] compare:[FBSDKAccessToken currentAccessToken].expirationDate] == NSOrderedAscending;
}

如果您有一个有效的 token ,您可以使用 [FBSDKAccessToken refreshCurrentAccessToken:] 刷新它。

关于ios - FBSDK 4.7.1登录时"You have already authorized yourApp",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33893338/

相关文章:

objective-c - AppDelegate 提示实现不完整,并在充满指针的调试 View 中崩溃

ios - 在 Xcode 6 中使用 AutoLayout 约束模拟方面适合行为

objective-c - 无法编译使用 Objective-C 包的 Swift 包

facebook - 喜欢按钮和隐私问题

mysql - OAuth(Facebook、Twitter)和基本登录 - 用户表

javascript - Facebook sharer.php 是否已更改为不再接受详细参数?

ios - IOS 中的 Google Place Search API

android - 一种在 flutter 中将最小化的应用程序置于前台的方法

ios - iOS 版 Google map 中的自定义用户位置点 (GMSMapview)

iphone - 如何使用谷歌驱动器在 ios 应用程序中获取视频和音频文件