通知栏未选中Tabbar

时间:2016-12-16 16:24:13

标签: swift storyboard tabbar

我在一个case中有一个navigationVIewController作为rootViewController,在一个case中有一个viewController作为rootViewController。

当rootViewController是viewController时,我无法使用下面的代码在didRecieveRemoteNotification方法中在该标签栏上显示viewController。

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {      

    if let type = userInfo["type"] as! String! {
        if UIApplication.shared.applicationState == .inactive {

            if self.window?.rootViewController as? UINavigationController != nil {
                //Works Fine
            } else {
                let storyBoard = UIStoryboard(name: "Main", bundle: nil)
                let myNavigationController = storyBoard.instantiateViewController(withIdentifier: "navBarID") as! UINavigationController
                let myTabbarController = myNavigationController.viewControllers[0] as! UITabBarController

                if type == "newsfeed" {
                    myTabbarController.selectedViewController = myTabbarController.viewControllers![3]
                } else if type == "event" {
                    myTabbarController.selectedViewController = myTabbarController.viewControllers![2]
                }                    
            }
        } else {
            // Foreground

        }
    }
}

0 个答案:

没有答案