我在我的应用程序中收到远程通知。以下代码写在AppDelegate
我收到通知时调用的文件中。
当应用程序在后台时收到通知
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
print("Notification Recieved")
UIApplication.shared.applicationIconBadgeNumber += 1
//process notification
for (key,val) in userInfo{
let nkey = key as! String
if nkey == "notificationType"{
let notificationType = val as! String
handleNotificationScreen(type: notificationType)
}
}
}
当应用程序处于后台并且用户单击该函数中的通知时,将调用上述函数userInfo
是一个包含通知信息的有效负载。在 userInfo 我notificationType
从包含各种值的服务器传递TASK
,KRA
等等
现在基于这些notificationType
值,我想启动不同的屏幕。如果 notificationType 是TASK
Then 在用户单击通知时启动任务屏幕。
我有一个TabBarController
有多个viewControllers
viewControllers = [taskController,messageController,notificationConroller,userProfileNavigationController,empCorner,perfomranceVC]
现在我应该怎么做才能在我的handleNotificationScreen(type: notificationType)
功能中启动屏幕。
func handleNotificationScreen(type: String){
switch type {
case "KRA":
print("anc")
case "TASK":
print("task")
case "EMPMONTH":
print("empMonth")
default:
print("none")
}
}
谢谢你们的帮助。