didReceiveRemoteNotification 在 运行 时来自任何地方的 presentViewController
didReceiveRemoteNotification presentViewController from anywhere when running
我正在尝试在收到远程通知时显示 UIViewController
。
我的代码可以正常工作,但是当应用程序是 运行 并且用户位于第一个 screen/navigation 堆栈以外的任何堆栈时,UIViewController
不会出现。
有人可以帮忙吗?注意我想在 UIViewController
出现时保留导航栏
当我尝试在其他地方显示 'UIViewController' 时收到此警告
警告:试图展示其视图不在 window 层次结构中!
提前致谢
这是我的 didReceiveRemoteNotification:
代码
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
var payload = userInfo
let requestID = payload["requestID"] as! String
let rootViewController = self.window!.rootViewController as! UINavigationController
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc : RequestViewController = storyboard.instantiateViewControllerWithIdentifier("RequestViewController") as! RequestViewController
vc.requestID = requestID
let navigationController = UINavigationController(rootViewController: vc)
rootViewController.presentViewController(navigationController, animated: true, completion: nil)
}
通过更改修复了它:
rootViewController.presentViewController(navigationController, animated: true, completion: nil)
至:
rootViewController.visibleViewController!.presentViewController(navigationController, animated: false, completion: nil)
我正在尝试在收到远程通知时显示 UIViewController
。
我的代码可以正常工作,但是当应用程序是 运行 并且用户位于第一个 screen/navigation 堆栈以外的任何堆栈时,UIViewController
不会出现。
有人可以帮忙吗?注意我想在 UIViewController
出现时保留导航栏
当我尝试在其他地方显示 'UIViewController' 时收到此警告
警告:试图展示其视图不在 window 层次结构中!
提前致谢
这是我的 didReceiveRemoteNotification:
func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {
var payload = userInfo
let requestID = payload["requestID"] as! String
let rootViewController = self.window!.rootViewController as! UINavigationController
let storyboard : UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
let vc : RequestViewController = storyboard.instantiateViewControllerWithIdentifier("RequestViewController") as! RequestViewController
vc.requestID = requestID
let navigationController = UINavigationController(rootViewController: vc)
rootViewController.presentViewController(navigationController, animated: true, completion: nil)
}
通过更改修复了它:
rootViewController.presentViewController(navigationController, animated: true, completion: nil)
至:
rootViewController.visibleViewController!.presentViewController(navigationController, animated: false, completion: nil)