Skip to content

Commit

Permalink
Fix scrumptious state change handler so that failed logins take user …
Browse files Browse the repository at this point in the history
…back to login screen as opposed to going to the announce view. Also improve the error alert views to translate the error code to a string.

Summary:
Fix scrumptious state change handler so that failed logins take user back to
login screen as opposed to going to the announce view. Also improve the error
alert views to translate the error code to a string.

Test Plan:
Ran scrumptious through various scenarios including successful logins,
 and cancelled logins (both via fast app switch or toggled ios6 app slider)

Revert Plan:

Reviewers: jacl

Reviewed By: jacl

Differential Revision: https://phabricator.fb.com/D589889

Task ID: 1778975
  • Loading branch information
chrisp-fb committed Oct 2, 2012
1 parent 0b3d28b commit d9661d3
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
2 changes: 2 additions & 0 deletions samples/Scrumptious/scrumptious/SCAppDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/

#import <UIKit/UIKit.h>
#import <FacebookSDK/FacebookSDK.h>

extern NSString *const SCSessionStateChangedNotification;

Expand All @@ -35,4 +36,5 @@ extern NSString *const SCSessionStateChangedNotification;
// FBSession, a login screen is displayed.
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI;

+ (NSString *)FBErrorCodeDescription:(FBErrorCode) code;
@end
45 changes: 40 additions & 5 deletions samples/Scrumptious/scrumptious/SCAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
* limitations under the License.
*/

#import <FacebookSDK/FacebookSDK.h>
#import "SCAppDelegate.h"
#import "SCViewController.h"
#import "SCLoginViewController.h"
Expand Down Expand Up @@ -82,8 +81,7 @@ - (void)sessionStateChanged:(FBSession *)session
[cacheDescriptor prefetchAndCacheForSession:session];
}
break;
case FBSessionStateClosed:
case FBSessionStateClosedLoginFailed: {
case FBSessionStateClosed: {
// FBSample logic
// Once the user has logged out, we want them to be looking at the root view.
UIViewController *topViewController = [self.navController topViewController];
Expand All @@ -92,9 +90,15 @@ - (void)sessionStateChanged:(FBSession *)session
[topViewController dismissModalViewControllerAnimated:NO];
}
[self.navController popToRootViewControllerAnimated:NO];

[FBSession.activeSession closeAndClearTokenInformation];

[self performSelector:@selector(showLoginView)
withObject:nil
afterDelay:0.5f];
}
break;
case FBSessionStateClosedLoginFailed: {
// if the token goes invalid we want to switch right back to
// the login view, however we do it with a slight delay in order to
// account for a race between this and the login view dissappearing
Expand All @@ -112,7 +116,8 @@ - (void)sessionStateChanged:(FBSession *)session
object:session];

if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Error: %@",
[SCAppDelegate FBErrorCodeDescription:error.code]]
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
Expand Down Expand Up @@ -178,4 +183,34 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
return YES;
}

+ (NSString *)FBErrorCodeDescription:(FBErrorCode) code {
switch(code){
case FBErrorInvalid :{
return @"FBErrorInvalid";
}
case FBErrorOperationCancelled:{
return @"FBErrorOperationCancelled";
}
case FBErrorLoginFailedOrCancelled:{
return @"FBErrorLoginFailedOrCancelled";
}
case FBErrorRequestConnectionApi:{
return @"FBErrorRequestConnectionApi";
}case FBErrorProtocolMismatch:{
return @"FBErrorProtocolMismatch";
}
case FBErrorHTTPError:{
return @"FBErrorHTTPError";
}
case FBErrorNonTextMimeTypeReturned:{
return @"FBErrorNonTextMimeTypeReturned";
}
case FBErrorNativeDialog:{
return @"FBErrorNativeDialog";
}
default:
return @"[Unknown]";
}
}

@end
9 changes: 6 additions & 3 deletions samples/Scrumptious/scrumptious/SCViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,10 @@ - (void)postOpenGraphAction {
}];
} else {
[[[UIAlertView alloc] initWithTitle:@"Result"
message:[NSString stringWithFormat:@"error: domain = %@, code = %d",
error.domain, error.code]
message:[NSString stringWithFormat:@"error: domain = %@, code = %@(%d)",
error.domain,
[SCAppDelegate FBErrorCodeDescription:error.code],
error.code]
delegate:nil
cancelButtonTitle:@"Thanks!"
otherButtonTitles:nil]
Expand Down Expand Up @@ -369,7 +371,8 @@ - (void)setPlaceCacheDescriptorForCoordinates:(CLLocationCoordinate2D)coordinate

- (void)loginViewController:(id)sender receivedError:(NSError *)error{
if (error) {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Error"
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[NSString stringWithFormat:@"Error: %@",
[SCAppDelegate FBErrorCodeDescription:error.code]]
message:error.localizedDescription
delegate:nil
cancelButtonTitle:@"OK"
Expand Down
2 changes: 1 addition & 1 deletion src/FBSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -1069,7 +1069,7 @@ - (void)authorizeUsingSystemAccountStore:(ACAccountStore*)accountStore
isReauthorize:NO];
} else {
// create an error object with additional info regarding failed login
NSError *err = [FBSession errorLoginFailedWithReason:nil
NSError *err = [FBSession errorLoginFailedWithReason:FBErrorLoginFailedReason
errorCode:nil
innerError:error];

Expand Down

0 comments on commit d9661d3

Please sign in to comment.