3
我正在使用推送通知在Swift中的应用程序。到目前为止,我有我的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(请参阅screenshot)。
当我运行我的应用程序和测试上轻敲推送通知,应用程序加载的行程表,我看到下面的日志中我的控制台:
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填充它?
我得到它的工作。我实例化和填充导航控制器的旅程列表视图和行程视图(以便我可以有后退按钮功能),然后我用导航控制器替换UIWindow实例上的rootViewController。 –