【发布时间】:2015-09-01 11:12:05
【问题描述】:
我有一个应用程序设置为接收推送通知。当用户收到通知时,我的 appDelegate 中有一个回调。如果应用程序处于非活动状态并且用户单击设备面板上的通知,我需要能够从这里开始。
应用程序的流程是一个登录视图控制器(如果 loginBool 为真,则跳过该控制器),它导致一个选项卡控制器。在选项卡控制器上,我有 3 个位置可以使用 id 为“FeedDetailedController”的同一 viewController。
这是我需要转入并传入我在通知中收到的变量的 FeedDetailedController。这个控制器可以从 3 个不同的地方访问,其中 2 个是带有表格视图的选项卡,当您单击一行时,它会传入一个变量并执行一个 segue。我需要从我的应用委托中模拟这个,即从通知中传递数据,就像我对行所做的那样。
目前的尝试:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
println("received a notification")
PFPush.handlePush(userInfo)
if application.applicationState == UIApplicationState.Inactive {
println("in the notification if with \(userInfo)")
if let info = userInfo["custom"] as? Dictionary<String, AnyObject> {
if let reportId = info["reportId"] as? String {
println("\nFrom APS-dictionary with key \"type\": \(reportId)")
//pass in reportId to the viewcontroller somehow
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier("NewFeedDetailedController") as! UIViewController
let navigationController = UINavigationController(rootViewController: vc)
self.window?.rootViewController?.presentViewController(navigationController, animated: true, completion: nil)
}
}
PFAnalytics.trackAppOpenedWithRemoteNotificationPayload(userInfo)
}
else{
println("in the notification else")
//this is when the app is active, do I need to detect which view controller I am currently on before I can seg???
}
}
当前代码给出以下信息:
Warning: Attempt to present <UINavigationController: 0x12ed763d0> on <UINavigationController: 0x12ed11ce0> whose view is not in the window hierarchy!
这是有道理的,但我不知道我应该如何从 appDelegate 代码中获得正确的层次结构
【问题讨论】:
标签: ios swift uiviewcontroller segue