从保存状态打开iOs应用程序

从保存状态打开iOs应用程序,ios,push-notification,Ios,Push Notification,我的应用程序有两个主要功能: 预约功能 消息传递功能 在启动期间,应用程序下载数据的初始部分(将日历与服务器同步,从服务器获取新消息)。我使用一个启动屏幕来完成这个过程 当应用程序进入保存状态时,用户可以通过聊天室的推送消息打开应用程序 我已经超越了 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { [[SKPayme

我的应用程序有两个主要功能:

  • 预约功能
  • 消息传递功能
  • 在启动期间,应用程序下载数据的初始部分(将日历与服务器同步,从服务器获取新消息)。我使用一个启动屏幕来完成这个过程

    当应用程序进入保存状态时,用户可以通过聊天室的推送消息打开应用程序

    我已经超越了

    - (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;
    }
    
    而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;
            }
        }
    }
    

    但不幸的是,取而代之的是ChatViewController,我得到了常规的启动屏幕。我的错误在哪里?

    我想您需要更换
    窗口,而不仅仅是
    rootViewController
    。我不能说我已经用故事板做到了,所以这只是一个猜测


    如果它不起作用,您需要删除故事板中的初始视图控制器指定,并在代码中为所有情况配置
    rootViewController

    didfishlaunchwithoptions
    中的完整代码是什么?您所说的“替换窗口”是什么意思?通过创建一个新的
    UIWindow
    ,将其设置为
    rootViewController
    ,将其保存为
    self.window
    ,然后在其上调用
    makeKeyAndVisible