如何检查用户是否使用iOS中的FBSDKLoginKit登录? [英] How to check if user is logged in with FBSDKLoginKit in iOS?

查看:184
本文介绍了如何检查用户是否使用iOS中的FBSDKLoginKit登录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在viewDidLoad中运行该应用程序时,我需要检查用户是否之前登录过.

When I run the app in viewDidLoad I need to check if user was logged in before or not.

if FBSDKAccessToken.currentAccessToken() != nil {
    print("1")
    presentViewController(controller, animated: true, completion: nil)
} else {
    print("2")
    let button = FBSDKLoginButton()
    button.delegate = self
    button.readPermissions = ["public_profile", "user_friends"]
    view.addSubview(button)
}

它总是打印"2".为什么?

推荐答案

AppDelegate中必须实现的两种方法必须:

Below two methods must be implemented in AppDelegate:

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
}

func application(application: UIApplication, openURL url: NSURL, sourceApplication: String?, annotation: AnyObject) -> Bool {
    return FBSDKApplicationDelegate.sharedInstance().application(application, openURL: url, sourceApplication: sourceApplication, annotation: annotation)
}

这篇关于如何检查用户是否使用iOS中的FBSDKLoginKit登录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆