从AppDelegate.swift执行Segue

时间:2015-11-29 13:07:10

标签: ios swift segue

我正在尝试在收到通知后执行segue。

以下是我在app app delegate中的内容。

func application(application: UIApplication, didReceiveRemoteNotification userInfo: [NSObject : AnyObject]) {


            let viewController = self.window!.rootViewController!.storyboard!.instantiateViewControllerWithIdentifier("SecondViewController")
            self.window?.rootViewController = viewController


    }

这会直接转到我希望它去的视图,但导航栏和标签栏是隐藏的。从app delegate,我如何从一个视图到另一个视图执行segue?所以我可以通过第二种观点达成,就像我从第一次看到的那样?

2 个答案:

答案 0 :(得分:2)

您尝试过:

viewController.performSegueWithIdentifier("my_segue_identifier", sender: nil)

更强大的方法是从AppDelegate广播NSNotification并让您的viewcontroller监听特定通知。

答案 1 :(得分:0)

我的解决方案: 在AppDelegate中添加公共变量(etc = 1)

    @available(iOS 10.0, *)
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
    print("User Info = ",response.notification.request.content.userInfo)
    flag = 1;   <---
    completionHandler()
}

并检查rootviewcontroller上的标志 - &gt; viewDidLoad中。如果这是真的吗?打电话给你的特殊赛段

    override func viewDidLoad() {
    super.viewDidLoad()
    if (flag == 1) {
        self.performSegue(withIdentifier: "roottanBildirimSegue", sender: self)
    }