简体   繁体   中英

Swift: Is it possible to avoid Facebook SDK 4.x “You have already authorized this app” dialog on login?

I have successfully implemented Facebook SDK in my iOS app, and can login / logout and display views according to FB login success.

However, there is an annoying dialog that keeps showing up past the initial login - "You have already authorized this app". Is there a way to avoid this?

这仅出现在模拟器上,而在我当前的实现中没有出现在设备上。

To add a more detailed answer: when you call the login method of the Facebook SDK, it will send the user through the login flow, regardless of the user already having authorized the app or not.

If you want to avoid this, you can add a manual check in your app to see if the user is already logged in and has a valid token, if this is the case, continue like you would before, otherwise trigger the login code.

The documentation has more details here, but basically it would roughly look like this (using v4.x of the SDK)

if ([FBSDKAccessToken currentAccessToken]) {
    // User is logged in, do work such as go to next view controller. 
    // You can also check if the token is still valid by using the
    // expirationDate property of the currentAccessToken
} else {
    // User is not logged in, start login flow
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM