Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS

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?

3 Answers

Hi, it looks like your app ether logs the user out somehow, once your user logs in the app an access token is stored in the device, but if you log the user out then the token is lost.

I don't think that's right. I get that message even though I still have the access token. I use this code to check for the token in my applicationDidBecomeActive method in my AppDelegate.swift, so I'm pretty sure I still retain the access token when I get this message.

if let fbAccessToken = FBSDKAccessToken.currentAccessToken() { return true } else { return false }

As per my experience, accessToken is not saved after the app was terminated. So the option here is to save the token manualy. And when your app starts, try to load it from CoreData, for example. If it's not there — start login dialog, else — make current access token from your saved data:

    let tokenString = fbLoginData!.tokenString!
    let appID = fbLoginData!.appID!
    let userID = fbLoginData!.userID!
    let expirationDate = fbLoginData!.expirationDate!
    let refreshDate = fbLoginData!.refreshDate!


    let accessToken = FBSDKAccessToken.init(tokenString: tokenString, permissions: permissions, declinedPermissions: declinedPermissions, appID: appID, userID: userID, expirationDate: expirationDate, refreshDate: refreshDate)