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

689 Views Asked by At

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?

2

There are 2 best solutions below

0
On BEST ANSWER

This only appears on the simulator, but not on the device with my current implementation.

0
On

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
}