简体   繁体   中英

iOs open app from preservation state

My app has 2 major functionalities:

  1. Appointment functionality
  2. Messaging functionality

During launch app downloads initial portion of data (syncs calendar with server, gets new messages from server). I use a splash screen for that process.

When app goes to preservation state user has ability to open app with push message from chat.

I've overridden

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[SKPaymentQueue defaultQueue] addTransactionObserver:[PurchaseHelper sharedInstance]];

    [Parse setApplicationId:kPLParseAppId clientKey:kPLParseClientId];
    [PFAnalytics trackAppOpenedWithLaunchOptions:launchOptions];

    [Crashlytics startWithAPIKey:@"mykey"];

    // social networks API        
    [PFFacebookUtils initializeFacebook];
    [[OkClient sharedInstance] initializeOdnoklassniki];
    [[VkClient sharedInstance] initializeVk];

    // load magical record support
    [MagicalRecord setupCoreDataStackWithStoreNamed:@"Model.sqlite"];

    // subscribe to notifications
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userDidLogin) name:kPLUserDidLoginNotification object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(userDidLogout) name:kPLUserDidLogoutNotification object:nil];

    // subscribe to pushes
    [application registerForRemoteNotificationTypes:UIRemoteNotificationTypeBadge|UIRemoteNotificationTypeAlert|UIRemoteNotificationTypeSound];

    UIColor *greenColor = [UIColor colorWithRed:111 green:221 blue:215 andAlpha:255];
    if([[UINavigationBar appearance] respondsToSelector:@selector(barTintColor)]) {
        // iOS7
        [UINavigationBar appearance].barTintColor = greenColor;
    } else {
        // older
        [UINavigationBar appearance].tintColor = greenColor;
    }

    [[UINavigationBar appearance] setTitleTextAttributes:
     @{NSFontAttributeName : [UIFont fontWithName:@"Circe-Regular" size:16.],
       NSForegroundColorAttributeName: [UIColor blackColor]}];


    [[UIBarButtonItem appearance] setTitleTextAttributes:@{NSFontAttributeName : [UIFont fontWithName:@"Circe-Regular" size:16.], NSForegroundColorAttributeName: [UIColor blackColor]} forState:UIControlStateNormal];

    // if app is started from push open chat
    if (launchOptions != nil) {
        NSDictionary *dictionary = [launchOptions objectForKey:UIApplicationLaunchOptionsRemoteNotificationKey];
        if (dictionary != nil) {
            ChatModel *chat = [self handlePushNotification:dictionary];
            [self launchChat:chat];
        }
    }

    // update purchase data if user is authenticated
    if ([[UserApiClient sharedInstance] isAuthenticated]) {
        [self updatePurchaseData];
    }

    // add styles
    [self addStyle];


    return YES;
}

And launchChat is:

- (void) launchChat:(ChatModel *) chat {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    // reveal controller
    UIViewController *revealController = [storyboard instantiateViewControllerWithIdentifier:@"AuxController"];

    ChatViewController *chatController = [storyboard instantiateViewControllerWithIdentifier:@"chatVC"];
    chatController.chatModelId = chat.objectID;


    self.window.rootViewController = revealController;

    for (UIViewController *controller in [revealController childViewControllers]){
        if ([controller isKindOfClass:[UINavigationController class]]) {
            UINavigationController *navController = (UINavigationController *) controller;
            [navController pushViewController:chatController animated:YES];
            break;
        }
    }
}

But unfortunately instead ChatViewController I get regular splash screen. Where my mistake is?

I guess you will need to replace the window instead of just the rootViewController . I can't say I've actually done that with a storyboard so it's a bit of a guess...

If it doesn't work, you would need to remove the initial view controller designation in the storyboard and configure the rootViewController in code for all cases.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM