【发布时间】:2016-01-08 10:44:55
【问题描述】:
我想打开一个特定的视图控制器(一个隐藏的视图控制器,因为它只有在收到某个推送通知时才能访问(它不能通过标签栏访问))并且我已经能够做到这一点,但我面临有问题..
我的应用有一个名为RootViewController 的自定义标签栏控制器。当您单击具有特殊值的通知时,它会显示一个警报视图,询问用户是否要打开通知。
通知触发将特定的视图控制器带到前面,但 问题是我无法再访问标签栏了。
我不知道如何实现。
这是我在AppDelegate.m中的代码:
var presentedVC = self.window?.rootViewController as? UINavigationController
while (presentedVC!.navigationController != nil) {
presentedVC = presentedVC!.navigationController
}
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let destinationViewController = storyboard.instantiateViewControllerWithIdentifier("PushNotificationView") as? NotTestViewController
destinationViewController?.url = self.url!
presentedVC?.presentViewController(destinationViewController!, animated: true, completion: nil)
})
)
alertCtrl.addAction(UIAlertAction(title: "Cancelar", style: .Destructive, handler: nil))
此代码可以正常工作,但不能实现所需的行为。
任何想法我缺少什么?
非常感谢
编辑
我已将RAMTabBarAnimationController 更改为TabBarController,因为RAMTabBarAnimationController 不继承自TabBarController。但我仍然看到相同的行为。
【问题讨论】:
-
presentedVC?.tabBarController?.selectedViewController?.pushViewController(destinationViewController!, animated: true)怎么样? -
使用 window.rootViewController presentViewController .....请记住 ....需要推送通知才能运行的应用程序将被拒绝
-
嗨@anishparajuli,你提到的解决方案是我已经拥有的。我首先实例化 rootViewController
var presentedVC = self.window?.rootViewController as? UITabBarController并获取目标视图控制器let destinationViewController = storyboard.instantiateViewControllerWithIdentifier("PushNotificationView") as? NotTestViewController最后你提到的presentedVC?.selectedViewController!.presentViewController(destinationViewController!, animated: true, completion: nil)它显示但标签栏在下面:/(ps:我的应用程序在没有通知的情况下工作):)
标签: ios iphone swift push-notification appdelegate