FBSession.openActiveSessionWithReadPermissions not calling completionHandler
facebook-graph-api, ios, swift
Solution
It's solved. I was missing the method AppDelegate.application:handleOpenURL -> Bool
Problem
I'm implementing OAuth login using Facebook SDK, but the FBSession.openActiveSessionWithReadPermissions:allowLoginUI:completionHandler method is not calling the completionHandler nor is it returning "true", which would indicate a cached token. Everything else seems to work fine, except this. What's wrong with this code? ``` var completionHandler: FBSessionStateHandler = { session, status, error in NSLog("token not cached"); if error { // Login failed for some reason, so we notify the delegate. self.delegate.didFailOpenningSession?(self, withError: ErrorUtility.error( code: .FailedOpenningSession, withFacebookError: error )); // Don't proceed on errors return; } // Session is now open, we should notify the delegate self.delegate.didOpenSession?(self); }; NSLog("here"); // Open the session, prompting the user if necessary. This might send the application to the background if FBSession.openActiveSessionWithReadPermissions(["public_profile"], allowLoginUI: true, completionHandler: completionHandler) { NSLog("Token cached"); // If we end up here, the session token must exist, so we now have an open session self.delegate.didOpenSession?(self); } ``` Edit: I forgot to mention that the NSLog logs "here", but not "Token cached" nor "token not cached" Edit: Now things got a bit stranger. When my app launches I show a screen with a Facebook login button. When the user presses the button the code above gets triggered. After I authorise the app, the app gets back to the same screen (it shouldn't, but I can't do it any other way until the completion handler gets called). Then I tried pressing the button again and now I do get the logs. This is what I get: ``` here token not cached here ``` The first line is from the first button press, the other two appear when I press it the second time. Now what's so odd about it? Shouldn't "token not cached" and "here" be reversed??? Is it calling the competionHandler from the last call or something? Nevermind, that much is fixed. Edit: one other thing. If I press the button multiple times, I always get "token not cached". I think it should be caching