Skip to content

Commit

Permalink
[ios-sdk] More Scrumptious cleanup.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
Chris Lang committed Jul 9, 2012
1 parent b09cd2e commit 674b90b
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 29 deletions.
1 change: 0 additions & 1 deletion samples/Scrumptious/scrumptious/SCAppDelegate.h
Expand Up @@ -15,7 +15,6 @@
*/

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

extern NSString *const SCSessionStateChangedNotification;

Expand Down
22 changes: 11 additions & 11 deletions samples/Scrumptious/scrumptious/SCAppDelegate.m
Expand Up @@ -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];
}
Expand All @@ -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];
}
Expand All @@ -87,7 +87,7 @@ - (void)sessionStateChanged:(FBSession *)session

[FBSession.activeSession closeAndClearTokenInformation];

[self showLoginViewWithError:(state == FBSessionStateClosedLoginFailed)];
[self showLoginView];
break;
default:
break;
Expand Down Expand Up @@ -151,7 +151,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[self openSession];
} else {
// No, display the login page.
[self showLoginViewWithError:NO];
[self showLoginView];
}

return YES;
Expand Down
3 changes: 3 additions & 0 deletions samples/Scrumptious/scrumptious/SCLoginViewController.h
Expand Up @@ -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
14 changes: 9 additions & 5 deletions samples/Scrumptious/scrumptious/SCLoginViewController.m
Expand Up @@ -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];
}
Expand All @@ -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 {
Expand Down
16 changes: 10 additions & 6 deletions samples/Scrumptious/scrumptious/SCLoginViewController.xib
Expand Up @@ -74,17 +74,21 @@
<object class="IBUIImageView" id="113215792">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">292</int>
<string key="NSFrame">{{20, 20}, {79, 80}}</string>
<string key="NSFrame">{{20, 26}, {74, 74}}</string>
<reference key="NSSuperview" ref="191373211"/>
<reference key="NSWindow"/>
<reference key="NSNextKeyView" ref="144313356"/>
<string key="NSReuseIdentifierKey">_NS:9</string>
<int key="IBUIContentMode">1</int>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">1</int>
<bytes key="NSRGB">MSAxIDEAA</bytes>
</object>
<int key="IBUIContentMode">4</int>
<bool key="IBUIUserInteractionEnabled">NO</bool>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
<object class="NSCustomResource" key="IBUIImage">
<string key="NSClassName">NSImage</string>
<string key="NSResourceName">app_icon.png</string>
<string key="NSResourceName">Icon-72.png</string>
</object>
</object>
<object class="IBUILabel" id="144313356">
Expand Down Expand Up @@ -158,7 +162,7 @@
</object>
<object class="IBUIImageView" id="6500122">
<reference key="NSNextResponder" ref="191373211"/>
<int key="NSvFlags">268</int>
<int key="NSvFlags">-2147483380</int>
<string key="NSFrame">{{20, 399}, {124, 41}}</string>
<reference key="NSSuperview" ref="191373211"/>
<reference key="NSWindow"/>
Expand Down Expand Up @@ -191,7 +195,7 @@
<reference key="NSNextKeyView" ref="113215792"/>
<object class="NSColor" key="IBUIBackgroundColor">
<int key="NSColorSpace">2</int>
<bytes key="NSRGB">MC4yMDc4NDMxNTQ3IDAuMzgwMzkyMTkzOCAwLjYyMzUyOTQzNDIAA</bytes>
<bytes key="NSRGB">MC4yMzEzNzI1NjUgMC4zNDkwMTk2MTY4IDAuNTk2MDc4NDU1NAA</bytes>
</object>
<object class="IBUISimulatedStatusBarMetrics" key="IBUISimulatedStatusBarMetrics"/>
<string key="targetRuntimeIdentifier">IBCocoaTouchFramework</string>
Expand Down Expand Up @@ -362,7 +366,7 @@
<bool key="IBDocument.PluginDeclaredDependenciesTrackSystemTargetVersion">YES</bool>
<int key="IBDocument.defaultPropertyAccessControl">3</int>
<dictionary class="NSMutableDictionary" key="IBDocument.LastKnownImageSizes">
<string key="app_icon.png">{256, 256}</string>
<string key="Icon-72.png">{72, 72}</string>
<string key="facebook.png">{196, 40}</string>
</dictionary>
<string key="IBCocoaTouchPluginVersion">1179</string>
Expand Down
6 changes: 3 additions & 3 deletions samples/Scrumptious/scrumptious/SCViewController.m
Expand Up @@ -353,8 +353,6 @@ - (void)dealloc {
_friendPickerController.delegate = nil;
_imagePicker.delegate = nil;
_imagePickerActionSheet.delegate = nil;

[[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)viewDidLoad {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions src/tests/FBTestSessionTests.m
Expand Up @@ -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];
}

Expand Down

0 comments on commit 674b90b

Please sign in to comment.