Permalink
Browse files

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.

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...
1 parent 0b3d28b commit d9661d313877fbd55bcd95fb4a6486cf4171b995 @chrisp-fb chrisp-fb committed Oct 2, 2012
View
2 samples/Scrumptious/scrumptious/SCAppDelegate.h
@@ -15,6 +15,7 @@
*/
#import <UIKit/UIKit.h>
+#import <FacebookSDK/FacebookSDK.h>
extern NSString *const SCSessionStateChangedNotification;
@@ -35,4 +36,5 @@ extern NSString *const SCSessionStateChangedNotification;
// FBSession, a login screen is displayed.
- (BOOL)openSessionWithAllowLoginUI:(BOOL)allowLoginUI;
++ (NSString *)FBErrorCodeDescription:(FBErrorCode) code;
@end
View
45 samples/Scrumptious/scrumptious/SCAppDelegate.m
@@ -14,7 +14,6 @@
* limitations under the License.
*/
-#import <FacebookSDK/FacebookSDK.h>
#import "SCAppDelegate.h"
#import "SCViewController.h"
#import "SCLoginViewController.h"
@@ -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];
@@ -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
@@ -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"
@@ -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
View
9 samples/Scrumptious/scrumptious/SCViewController.m
@@ -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]
@@ -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"
View
2 src/FBSession.m
@@ -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];

0 comments on commit d9661d3

Please sign in to comment.