【发布时间】:2018-07-10 11:10:58
【问题描述】:
我在我的应用程序中收到远程通知。以下代码写在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 然后当用户点击通知时启动任务屏幕。
我有一个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")
}
}
谢谢大家的帮助。
【问题讨论】:
标签: ios swift uitabbarcontroller appdelegate remote-notifications