Join the guys.
Everything is done through the Facebook iOS SDK, and this SDK itself looks at what to do and how to behave:
If the user has entered the data into the system account, then he will be used, otherwise the SDK will try to open the Facebook App, if the application is not installed, it will open Safari.
In order to be able to return to the application after logging in via the Safari or Facebook App, then in Info.plist you need to add support for the URL scheme, such as fb $ app_id.
In principle, everything is rather trivial and repeatedly painted, but I would like to share a little different experience, namely how to connect the iOS app with the server backend and what can be stepped on.
This is not the only right decision, but in my opinion it is quite acceptable and quite “secular”.
In the mobile application you need to get the user data:
[FBSession openActiveSessionWithReadPermissions:@[@"email"] allowLoginUI:YES completionHandler:^(FBSession *session, FBSessionState status, NSError *error) { if (session.isOpen && _successCallback) { _successCallback(session.accessTokenData.accessToken); } else if (_failureCallback) { _failureCallback([[TDError alloc] initWithError:error]); } }];
pull out the auth_token and send it to the server, after which the server application should knock somewhere like facebook.com/api/me with this token, and if valid data has arrived, then we have everything to register a new user, or find the old one and log in him.
PS at the moment when the user logs out of the mobile application, you also need to drop the session in the FB SDK, because it caches the session, and if the user has changed something on the web on the FB (for example, the application has dropped access), the open session will still return on the device and token, but the fact that the token is invalid will be found out only on the server)
Cleaning an FB session:
[FBSession.activeSession closeAndClearTokenInformation]; [FBSession.activeSession close]; [FBSession setActiveSession:nil];
ZY Please forgive me if I wrote something wrong and misled :)