From 674b90bd77a83a31d14f6be5f098d98674e062e3 Mon Sep 17 00:00:00 2001 From: Chris Lang Date: Fri, 6 Jul 2012 14:23:19 -0700 Subject: [PATCH] [ios-sdk] More Scrumptious cleanup. Summary: In working through the tutorial and recent FBSession changes, I found a few more places where Scrumptious could be cleaned up. Also fixed a unit test that wasn't ever actually asserting anything succeeded. Test Plan: - Ran Scrumptious - Ran unit tests Revert Plan: Reviewers: jacl, mmarucheck, gregschechte, ayden Reviewed By: jacl CC: msdkexp@ Differential Revision: https://phabricator.fb.com/D513407 --- .../Scrumptious/scrumptious/SCAppDelegate.h | 1 - .../Scrumptious/scrumptious/SCAppDelegate.m | 22 +++++++++---------- .../scrumptious/SCLoginViewController.h | 3 +++ .../scrumptious/SCLoginViewController.m | 14 +++++++----- .../scrumptious/SCLoginViewController.xib | 16 +++++++++----- .../scrumptious/SCViewController.m | 6 ++--- src/tests/FBTestSessionTests.m | 6 ++--- 7 files changed, 39 insertions(+), 29 deletions(-) diff --git a/samples/Scrumptious/scrumptious/SCAppDelegate.h b/samples/Scrumptious/scrumptious/SCAppDelegate.h index dbf032afda..8332f93882 100644 --- a/samples/Scrumptious/scrumptious/SCAppDelegate.h +++ b/samples/Scrumptious/scrumptious/SCAppDelegate.h @@ -15,7 +15,6 @@ */ #import -#import extern NSString *const SCSessionStateChangedNotification; diff --git a/samples/Scrumptious/scrumptious/SCAppDelegate.m b/samples/Scrumptious/scrumptious/SCAppDelegate.m index 2c54501a08..ab8ebb4878 100644 --- a/samples/Scrumptious/scrumptious/SCAppDelegate.m +++ b/samples/Scrumptious/scrumptious/SCAppDelegate.m @@ -26,33 +26,32 @@ @interface SCAppDelegate () @property (strong, nonatomic) UINavigationController *navController; @property (strong, nonatomic) SCViewController *mainViewController; -- (FBSession*)createNewSession; -- (void)showLoginViewWithError:(BOOL)error; +- (void)showLoginView; @end @implementation SCAppDelegate @synthesize window = _window; -@synthesize mainViewController = _viewController; +@synthesize mainViewController = _mainViewController; @synthesize navController = _navController; #pragma mark - #pragma mark Facebook Login Code -- (void)showLoginViewWithError:(BOOL)error { +- (void)showLoginView { UIViewController *topViewController = [self.navController topViewController]; UIViewController *modalViewController = [topViewController modalViewController]; // FBSample logic - // If the login screen is not already displayed, display it. If we got an error, notify - // the controller. + // If the login screen is not already displayed, display it. If the login screen is displayed, then + // getting back here means the login in progress did not successfully complete. In that case, + // notify the login view so it can update its UI appropriately. if (![modalViewController isKindOfClass:[SCLoginViewController class]]) { SCLoginViewController* loginViewController = [[SCLoginViewController alloc]initWithNibName:@"SCLoginViewController" bundle:nil]; [topViewController presentModalViewController:loginViewController animated:NO]; - } - if (error) { + } else { SCLoginViewController* loginViewController = (SCLoginViewController*)modalViewController; [loginViewController loginFailed]; } @@ -74,7 +73,8 @@ - (void)sessionStateChanged:(FBSession *)session } // FBSample logic - // Pre-fetch and cache the friends for the friend picker as soon as possible + // Pre-fetch and cache the friends for the friend picker as soon as possible to improve + // responsiveness when the user tags their friends. FBCacheDescriptor *cacheDescriptor = [FBFriendPickerViewController cacheDescriptor]; [cacheDescriptor prefetchAndCacheForSession:session]; } @@ -87,7 +87,7 @@ - (void)sessionStateChanged:(FBSession *)session [FBSession.activeSession closeAndClearTokenInformation]; - [self showLoginViewWithError:(state == FBSessionStateClosedLoginFailed)]; + [self showLoginView]; break; default: break; @@ -151,7 +151,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:( [self openSession]; } else { // No, display the login page. - [self showLoginViewWithError:NO]; + [self showLoginView]; } return YES; diff --git a/samples/Scrumptious/scrumptious/SCLoginViewController.h b/samples/Scrumptious/scrumptious/SCLoginViewController.h index c1e884235a..653ec39058 100644 --- a/samples/Scrumptious/scrumptious/SCLoginViewController.h +++ b/samples/Scrumptious/scrumptious/SCLoginViewController.h @@ -23,6 +23,9 @@ // using SSO if possible, otherwise using the web dialog UI. @interface SCLoginViewController : UIViewController +// FBSample logic +// This method should be called to indicate that a login which was in progress has +// resulted in a failure. - (void)loginFailed; @end diff --git a/samples/Scrumptious/scrumptious/SCLoginViewController.m b/samples/Scrumptious/scrumptious/SCLoginViewController.m index 790ae32ecb..a6f051a9f3 100644 --- a/samples/Scrumptious/scrumptious/SCLoginViewController.m +++ b/samples/Scrumptious/scrumptious/SCLoginViewController.m @@ -34,6 +34,8 @@ @implementation SCLoginViewController - (IBAction)performLogin:(id)sender { [self.spinner startAnimating]; + // FBSample logic + // The user has initiated a login, so call the openSession method. SCAppDelegate *appDelegate = [UIApplication sharedApplication].delegate; [appDelegate openSession]; } @@ -53,17 +55,19 @@ - (void)viewWillAppear:(BOOL)animated { } - (void)loginFailed { - // User switched back to the app without authorizing. Stay here, but - // stop the spinner. + // FBSample logic + // Our UI is quite simple, so all we need to do in the case of the user getting + // back to this screen without having been successfully authorized is to + // stop showing our activity indicator. The user can initiate another login + // attempt by clicking the Login button again. [self.spinner stopAnimating]; } - (void)viewDidUnload { - [super viewDidUnload]; - // Release any retained subviews of the main view. - // e.g. self.myOutlet = nil; self.spinner = nil; self.loginButton = nil; + + [super viewDidUnload]; } - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { diff --git a/samples/Scrumptious/scrumptious/SCLoginViewController.xib b/samples/Scrumptious/scrumptious/SCLoginViewController.xib index 43bbfce93d..a056be2dc2 100644 --- a/samples/Scrumptious/scrumptious/SCLoginViewController.xib +++ b/samples/Scrumptious/scrumptious/SCLoginViewController.xib @@ -74,17 +74,21 @@ 292 - {{20, 20}, {79, 80}} + {{20, 26}, {74, 74}} _NS:9 - 1 + + 1 + MSAxIDEAA + + 4 NO IBCocoaTouchFramework NSImage - app_icon.png + Icon-72.png @@ -158,7 +162,7 @@ - 268 + -2147483380 {{20, 399}, {124, 41}} @@ -191,7 +195,7 @@ 2 - MC4yMDc4NDMxNTQ3IDAuMzgwMzkyMTkzOCAwLjYyMzUyOTQzNDIAA + MC4yMzEzNzI1NjUgMC4zNDkwMTk2MTY4IDAuNTk2MDc4NDU1NAA IBCocoaTouchFramework @@ -362,7 +366,7 @@ YES 3 - {256, 256} + {72, 72} {196, 40} 1179 diff --git a/samples/Scrumptious/scrumptious/SCViewController.m b/samples/Scrumptious/scrumptious/SCViewController.m index e694435474..da1264f790 100644 --- a/samples/Scrumptious/scrumptious/SCViewController.m +++ b/samples/Scrumptious/scrumptious/SCViewController.m @@ -353,8 +353,6 @@ - (void)dealloc { _friendPickerController.delegate = nil; _imagePicker.delegate = nil; _imagePickerActionSheet.delegate = nil; - - [[NSNotificationCenter defaultCenter] removeObserver:self]; } - (void)viewDidLoad { @@ -365,7 +363,7 @@ - (void)viewDidLoad { // Get the CLLocationManager going. self.locationManager = [[CLLocationManager alloc] init]; self.locationManager.delegate = self; - self.locationManager.desiredAccuracy = kCLLocationAccuracyBest; + self.locationManager.desiredAccuracy = kCLLocationAccuracyNearestTenMeters; // We don't want to be notified of small changes in location, preferring to use our // last cached results, if any. self.locationManager.distanceFilter = 50; @@ -411,6 +409,8 @@ -(void)logoutButtonWasPressed:(id)sender { - (void)viewDidUnload { [super viewDidUnload]; + [[NSNotificationCenter defaultCenter] removeObserver:self]; + // Release any retained subviews of the main view. self.placePickerController = nil; self.friendPickerController = nil; diff --git a/src/tests/FBTestSessionTests.m b/src/tests/FBTestSessionTests.m index d616a98c5b..06a53a0281 100644 --- a/src/tests/FBTestSessionTests.m +++ b/src/tests/FBTestSessionTests.m @@ -82,15 +82,15 @@ - (void)testSharedUserDoesntCreateUnnecessaryUsers [self loginSession:session]; [session close]; -// int startingUserCount = [self countTestUsers]; + int startingUserCount = [self countTestUsers]; // Try getting another shared user. session = [FBTestSession sessionWithSharedUserWithPermissions:nil]; [self loginSession:session]; -// int endingUserCount = [self countTestUsers]; + int endingUserCount = [self countTestUsers]; -// STAssertEquals(startingUserCount, endingUserCount, @"differing counts"); + STAssertEquals(startingUserCount, endingUserCount, @"differing counts"); [session close]; }