【问题标题】:Performe, navigate, to child view from App Delegate从 App Delegate 执行、导航到子视图
【发布时间】:2015-05-03 02:30:30
【问题描述】:

当应用程序通过推送通知启动时,我正在尝试打开子视图(PostReaderViewController,Image 上的第四个视图)。故事板图像: 这是我的代码:

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

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

【问题讨论】:

    标签: ios objective-c iphone uinavigationcontroller swrevealviewcontroller


    【解决方案1】:

    self.window.rootViewController 需要在viewDidLoadviewDidAppear 中执行演示。如果你早点这样做,那么 rootViewController 将是 nil 或者视图控制器层次结构将不会处于可以容纳演示文稿的状态。

    【讨论】:

      【解决方案2】:

      解决这个问题:

      首先我创建了 Global BOOL 变量,然后在 AppDelegate 中我将此 var 设置为 YES,如果应用程序通过推送通知启动,如下所示:

      //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
                       }
      

      【讨论】:

        猜你喜欢
        • 2015-01-24
        • 2018-12-05
        • 1970-01-01
        • 2012-10-30
        • 2020-12-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2020-10-02
        相关资源
        最近更新 更多