简体   繁体   English

iOs从保存状态开始打开应用

[英]iOs open app from preservation state

My app has 2 major functionalities: 我的应用程序具有2个主要功能:

  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: 而launchChat是:

- (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 . 我猜您将需要替换window而不仅仅是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. 如果不起作用,则需要在情节rootViewController中删除初始的视图控制器名称,并针对所有情况在代码中配置rootViewController

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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