打开通知特定视图 [英] Open notification to specific view

查看:90
本文介绍了打开通知特定视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在斯威夫特使用推送通知工作的一个应用程序。到目前为止,我有以下的code在我的AppDelegate:

I'm working on an app in Swift using push notifications. So far I have the following code in my AppDelegate:

  func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
    println("Received alert and opened it")
    debugPrintln(userInfo)

    if application.applicationState == UIApplicationState.Active {
      // App in foreground
      println("App in foreground already")
    } else {
      // App in background
      if let tripId = (userInfo["trip"] as? String)?.toInt() {
        println(tripId)
        Trips.load(tripId) { (responseCode, trip) in
          debugPrintln("Got the trip")
          if let trip = trip {
            if let window = self.window {
              if let rootViewController = window.rootViewController {
                if let storyboard = rootViewController.storyboard {
                  let viewController = storyboard.instantiateViewControllerWithIdentifier("Trip") as! TripViewController
                  viewController.trip = trip
                  rootViewController.presentViewController(viewController, animated: true, completion: nil)
                } else {
                  println("No storyboard")
                }
              } else {
                println("No root view controller")
              }
            } else {
              println("No window")
            }
          }
        }
      } else {
        println("Failed to get trip id")
      }
    }
  }

,故事情节构成的,即应用程序第一次打开时,它会打开到LoginViewController,检查登录状态,并重定向到包含NavigationController车次列表。从列表中,用户可以点击一趟打开TripViewController(见截图)。

当我运行我的应用程序和测试敲击推送通知,应用程序加载的行程表,我看到下面的日志中我的控制台:

When I run my app and test tapping on a push notification, the app loads the trip list and I see the following log in my console:

2015-09-04 09:50:07.158 GoDriver[883:377922] Warning: Attempt to present <GoDriver.TripViewController: 0x15f5b260> on <GoDriver.LoginViewController: 0x15d910e0> whose view is not in the window hierarchy!

我必须加载了我的导航控制器,并与TripViewController填充呢?

Do I have to load up my Navigation Controller and populate it with the TripViewController?

推荐答案

如果您使用的是 UIStoryBoard ,并使用 initialViewController ,iOS设备会自动要紧的IE加载它,如果需要创建navigationController,它负载窗口。

If you are using UIStoryBoard and using the initialViewController, iOS automatically does the needful i.e loads it up, creates navigationController if needed and loads it to window.

但是,在这种情况下,你需要手动做到这一点位。您需要创建一个UINavigationController,你TripViewController填充它,然后用的UIWindow 把它捞起来。

However in this case you will need to do this bit manually. You would need to create a UINavigationController, populate it with your TripViewController and hook it with UIWindow.

这篇关于打开通知特定视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆