I have just found this issue whilst testing my application and it is really starting to annoy me. So what the environment is like is as follows :
- No Facebook App installed
- User is logged into iOS System Account (Under settings -> Facebook)
When my app attempts to authenticate the user for the first time it provides this wall of text : ( I tried cleaning it up a little)
2014-01-30 15:20:31.439 Unifeed[2140:70b] Session is <FBSession: 0xb74f9e0, state:
FBSessionStateClosedLoginFailed,
loginHandler: 0x0, appID: *************, urlSchemeSuffix: ,
tokenCachingStrategy:<FBSessionTokenCachingStrategy: 0xb73bd90>,
expirationDate: (null),
refreshDate: (null), attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(null)>
2014-01-30 15:20:31.440 Unifeed[2140:70b] Session closed
2014-01-30 15:20:31.440 Unifeed[2140:70b] User logged out
2014-01-30 15:20:31.441 Unifeed[2140:70b] Error occured Error Domain=com.facebook.sdk Code=2
"The operation couldn’t be completed. (com.facebook.sdk error 2.)"
UserInfo=********
{com.facebook.sdk:ErrorLoginFailedReason=com.facebook.sdk:SystemLoginCancelled,
com.facebook.sdk:ErrorInnerErrorKey=Error Domain=com.apple.accounts Code=7 "The operation
couldn’t be completed. (com.apple.accounts error 7.)",
com.facebook.sdk:ErrorSessionKey=<FBSession: 0xb74f9e0, state: FBSessionStateClosedLoginFailed,
loginHandler: 0x0, appID: ************, urlSchemeSuffix:
, tokenCachingStrategy:<FBSessionTokenCachingStrategy:
0xb73bd90>, expirationDate: (null), refreshDate: (null),
attemptedRefreshDate: 0001-12-30 00:00:00 +0000, permissions:(null)>}
2014-01-30 15:20:31.441 Unifeed[2140:70b] User cancelled login
2014-01-30 15:20:31.445 Unifeed[2140:70b] User logged out
I know thats slightly confusing but my take on it is its erring out because it thinks the user cancelled the login process. The thing is I never see the little pop up asking me if I want to login or to accept the permissions.... So I added the Facebook app to the phone and it worked... well thats great but what if I have a user with not App but they have FB logged in on the phone.... Anyone have any ideas?
My code for authentication is as follows : (Pretty much just a little modified from FB website)
- (void) facebookSessionChange {
// If the session state is any of the two "open" states when the button is clicked
if (FBSession.activeSession.state == FBSessionStateOpen
|| FBSession.activeSession.state == FBSessionStateOpenTokenExtended) {
// Close the session and remove the access token from the cache
// The session state handler (in the app delegate) will be called automatically
[FBSession.activeSession closeAndClearTokenInformation];
// If the session state is not any of the two "open" states when the button is clicked
} else {
// Open a session showing the user the login UI
[FBSession openActiveSessionWithReadPermissions:permissions
allowLoginUI:YES
completionHandler:
^(FBSession *session, FBSessionState state, NSError *error) {
[self sessionStateChanged:session state:state error:error];
}];
}
}
- (void)sessionStateChanged:(FBSession *)session state:(FBSessionState) state error:(NSError *)error
{
NSLog(@"Session is %@", session);
// If the session was opened successfully
if (!error && state == FBSessionStateOpen){
NSLog(@"Session opened");
// Show the user the logged-in UI
[self userLoggedIn];
return;
}
if (state == FBSessionStateClosed || state == FBSessionStateClosedLoginFailed){
// If the session is closed
NSLog(@"Session closed");
// Show the user the logged-out UI
[self userLoggedOut];
}
// Handle errors
if (error){
NSLog(@"Error occured %@", error);
if ([FBErrorUtility shouldNotifyUserForError:error] == YES){
NSLog(@"Error occured %@", error);
} else {
// If the user cancelled login, do nothing
if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryUserCancelled) {
NSLog(@"User cancelled login");
// Handle session closures that happen outside of the app
} else if ([FBErrorUtility errorCategoryForError:error] == FBErrorCategoryAuthenticationReopenSession){
NSLog(@"Session is no longer valid");
} else {
//Get more error information from the error
NSDictionary *errorInformation = [[[error.userInfo objectForKey:@"com.facebook.sdk:ParsedJSONResponseKey"] objectForKey:@"body"] objectForKey:@"error"];
NSLog(@"Error occured : %@", [errorInformation objectForKey:@"message"]);
}
}
// Clear this token
[FBSession.activeSession closeAndClearTokenInformation];
// Show the user the logged-out UI
[self userLoggedOut];
}
}
// Show the user the logged-out UI
- (void)userLoggedOut
{
NSLog(@"User logged out");
}
// Show the user the logged-in UI
- (void)userLoggedIn
{
NSLog(@"User Logged in");
[_delegate doneLogginginToFb];
}
I have tried changing the way I authenticate but always run into the same problem... Any ideas?
Thanks
A