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

时间:2014-04-03 11:38:14

标签: ios push-notification

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

  1. 约会功能
  2. 信息功能
  3. 在启动应用程序期间下载数据的初始部分(与服务器同步日历,从服务器获取新消息)。我使用启动画面进行该过程。

    当应用程序进入保存状态时,用户可以使用来自聊天的推送消息打开应用程序。

    我已经覆盖了

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

    启动即:

    - (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我得到了常规的启动画面。我的错误在哪里?

1 个答案:

答案 0 :(得分:1)

我想你需要替换window而不是rootViewController。我不能说我实际上是用故事板做的,所以这有点猜测......

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