Skip to content

Commit

Permalink
Restore previously-selected account after launch on iPad
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Zorn committed May 26, 2012
1 parent 4dc8656 commit 2b43c86
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
15 changes: 14 additions & 1 deletion Classes/AppSalesAppDelegate.m
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -82,7 +82,17 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(


[self showPasscodeLockIfNeeded]; [self showPasscodeLockIfNeeded];
if (iPad) { if (iPad) {
[self selectAccount:nil]; //Restore previously-selected account:
NSString *accountIDURIString = [[NSUserDefaults standardUserDefaults] stringForKey:kSettingSelectedAccountID];
if (accountIDURIString) {
NSManagedObjectID *accountID = [self.managedObjectContext.persistentStoreCoordinator managedObjectIDForURIRepresentation:[NSURL URLWithString:accountIDURIString]];
ASAccount *account = (ASAccount *)[self.managedObjectContext objectWithID:accountID];
if (account) {
[self accountsViewController:nil didSelectAccount:account];
}
} else {
[self selectAccount:nil];
}
} }


return YES; return YES;
Expand All @@ -99,6 +109,9 @@ - (void)accountsViewController:(AccountsViewController *)viewController didSelec
{ {
[self.accountsPopover dismissPopoverAnimated:YES]; [self.accountsPopover dismissPopoverAnimated:YES];
[self loadAccount:account]; [self loadAccount:account];

NSString *accountIDURIString = [[[account objectID] URIRepresentation] absoluteString];
[[NSUserDefaults standardUserDefaults] setObject:accountIDURIString forKey:kSettingSelectedAccountID];
} }


- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex - (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
Expand Down
2 changes: 2 additions & 0 deletions OtherSources/GlobalSettings.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@
#define kSettingDashboardShowWeeks @"DashboardShowWeeks" #define kSettingDashboardShowWeeks @"DashboardShowWeeks"
#define kSettingDownloadPayments @"DownloadPayments" #define kSettingDownloadPayments @"DownloadPayments"


#define kSettingSelectedAccountID @"SelectedAccountID"

#define ASWillShowPasscodeLockNotification @"ASWillShowPasscodeLockNotification" #define ASWillShowPasscodeLockNotification @"ASWillShowPasscodeLockNotification"

0 comments on commit 2b43c86

Please sign in to comment.