运行

时间:2015-08-30 19:00:45

标签: ios swift uinavigationcontroller push-notification presentviewcontroller

我正在尝试在收到远程通知时提供UIViewController

我的代码可以指向,但是当应用程序运行且用户位于第一个屏幕/导航堆栈以外的任何位置时,UIViewController不会显示。

有人可以帮忙吗?注意我想在显示UIViewController时保留导航栏

当我尝试在其他地方展示'UIViewController'时,我收到此警告

警告:尝试显示其视图不在窗口层次结构中!

提前致谢

以下是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)

}

1 个答案:

答案 0 :(得分:1)

通过更改:

修正了它
rootViewController.presentViewController(navigationController, animated: true, completion: nil)

为:

rootViewController.visibleViewController!.presentViewController(navigationController, animated: false, completion: nil)