从App Delegate执行,导航到子视图

时间:2015-03-02 16:35:37

标签: ios objective-c iphone uinavigationcontroller swrevealviewcontroller

当我通过Push通知启动应用程序时,我试图打开子视图(PostReaderViewController,Image上的第四个视图)。故事板图片: enter image description here 这是我的代码:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
      ... 
    //Detecting if the app was lunched by clicking on push notification :
    NSDictionary *userInfo = [launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
    NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];

    if(apsInfo) {
        UIStoryboard *mainstoryboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
        PostReaderViewController* postReader = (PostReaderViewController *)[mainstoryboard instantiateViewControllerWithIdentifier:@"postReaderView"];
        CostumSDPost *tempPost = [[CostumSDPost alloc] init];
        tempPost.ID = userInfo[@"post_id"];
        postReader.thePost = tempPost;
        [self.window.rootViewController presentViewController:postReader animated:YES completion:NULL];
        //userInfo[@"post_id"]);
    }
    return YES;
}

当我通过推送通知启动我的APP时,没有显示错误,但不幸的是它启动并显示默认视图(第三个图像查看)。
请注意,我使用SWRevealMenu并且初始点(图像上的第一个视图)是显示视图控制器

2 个答案:

答案 0 :(得分:0)

self.window.rootViewController需要在viewDidLoadviewDidAppear中执行演示。如果您之前执行此操作,则rootViewController将为nil,或者视图控制器层次结构不会处于可以容纳演示文稿的状态。

答案 1 :(得分:0)

解决这个问题:

首先我已经创建了Global BOOL变量然后在AppDelegate中我将此var设置为YES如果应用程序通过push notif如下所示:

//Detecting if the app was lunched by clicking on push notification :
    NSDictionary *userInfo = [launchOptions valueForKey:@"UIApplicationLaunchOptionsRemoteNotificationKey"];
    NSDictionary *apsInfo = [userInfo objectForKey:@"aps"];
    if(apsInfo) { 
        // Set my global Var to YES
        GlobalSingleton *global = [GlobalSingleton sharedInstance];
        global.displayFirstPost = YES; }

然后在我的主屏幕中,我检查此变量是否== YES然后导航到下一个屏幕,否则显示主屏幕:

GlobalSingleton *global = [GlobalSingleton sharedInstance];
             if (global.displayFirstPost) {
                 // NAvigation code to the third Screen
                 }