I am developing live chat app with Firebase
so everything works fine for me but I am redirecting directly to viewcontroller
as per notification type and I am redirected successfully but the issue is that when app launch first time than I am getting crash and get an error like below
Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value
Here is my code for didReceiveRemoteNotification
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
let notificationType = userInfo["notification_type"] as! String //i am getting crash here
if notificationType == "news_notification"{
let rootViewController = self.window?.rootViewController as! UINavigationController
let storyboard = UIStoryboard(name: "Settings", bundle: nil)
let VC = storyboard.instantiateViewController(withIdentifier: "NewsDetailViewController") as! NewsDetailViewController
if let aps = userInfo["aps"] as? NSDictionary{
if let alert = aps["alert"] as? NSDictionary{
if let body = alert["body"] as? String{
print(body)
VC.name1 = body
}
if let title = alert["title"] as? String{
print(title)
VC.name = title
}
}
}
VC.vcValue = "1"
rootViewController.pushViewController(VC, animated: true)
}
}
if I comment this code and then login successfully after login I uncomment this code that its work fine but only first-time launch I am getting error