Skip to content
Browse files

Restore previously-selected account after launch on iPad

  • Loading branch information...
1 parent 4dc8656 commit 2b43c86b11880c5a4b34bc097f98dda62942a5ea Ole Zorn committed May 26, 2012
Showing with 16 additions and 1 deletion.
  1. +14 −1 Classes/AppSalesAppDelegate.m
  2. +2 −0 OtherSources/GlobalSettings.h
View
15 Classes/AppSalesAppDelegate.m
@@ -82,7 +82,17 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
[self showPasscodeLockIfNeeded];
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;
@@ -99,6 +109,9 @@ - (void)accountsViewController:(AccountsViewController *)viewController didSelec
{
[self.accountsPopover dismissPopoverAnimated:YES];
[self loadAccount:account];
+
+ NSString *accountIDURIString = [[[account objectID] URIRepresentation] absoluteString];
+ [[NSUserDefaults standardUserDefaults] setObject:accountIDURIString forKey:kSettingSelectedAccountID];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
View
2 OtherSources/GlobalSettings.h
@@ -13,4 +13,6 @@
#define kSettingDashboardShowWeeks @"DashboardShowWeeks"
#define kSettingDownloadPayments @"DownloadPayments"
+#define kSettingSelectedAccountID @"SelectedAccountID"
+
#define ASWillShowPasscodeLockNotification @"ASWillShowPasscodeLockNotification"

0 comments on commit 2b43c86

Please sign in to comment.
Something went wrong with that request. Please try again.