gpt4 book ai didi

ios - 单击带有 Reveal 的推送通知导航到特定 View

转载 作者:行者123 更新时间:2023-11-28 12:17:37 26 4
gpt4 key购买 nike

我想在单击推送通知时导航到特定的 View Controller 。

我已经在我的 didReceiveRemoteNotification 方法中编写了这段代码。

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier: "deals") as! FYIDealsVC
let naviVC:UINavigationController? = self.window?.rootViewController?.revealViewController().frontViewController as? UINavigationController
naviVC?.pushViewController(vc, animated: true)
}

但它给了我这个使应用程序崩溃的错误。

fatal error: unexpectedly found nil while unwrapping an Optional value

有很多帖子介绍了导航 Controller 或只是介绍了 View Controller 。但我想使用 reveal 导航到特定 View 。

如有任何帮助,我们将不胜感激。

最佳答案

这是另一个解决方案试试这个:-

第一个选项:-

    let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier:
"deals") as! FYIDealsVC

// setup revelview controller and root with window

self.window?.rootViewController = //object of revelViewController
self.window?.makeKeyAndVisible()

第二个选项:-

 //  in Landing Screen from where you can easily navigate to the target 
viewcontroller :-

在 Landing VC 中:-

   viewdidload:- 
NotificationCenter.default.addObserver(self, selector:
#selector(self.navigationForNotification(notification:)), name:
NSNotification.Name(rawValue:PushNavigationIdentifier), object: nil)


// Selector Method :-

func navigationForNotification(notification:Notification) {
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewController(withIdentifier:
"deals") as! FYIDealsVC
self.navigationController?.pushViewController(vc, animated: true)
}


in appDelegate :-
func application(_ application: UIApplication,
didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
NotificationCenter.default.post(name:
NSNotification.Name(PushNavigationIdentifier), object: userInfo)

}

关于ios - 单击带有 Reveal 的推送通知导航到特定 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45934868/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com