Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios TabItem with BadgeValue仅在我从通知触发器启动应用程序时显示_Ios_Swift3_Push Notification_Apple Push Notifications_Ios10 - Fatal编程技术网

Ios TabItem with BadgeValue仅在我从通知触发器启动应用程序时显示

Ios TabItem with BadgeValue仅在我从通知触发器启动应用程序时显示,ios,swift3,push-notification,apple-push-notifications,ios10,Ios,Swift3,Push Notification,Apple Push Notifications,Ios10,我有一个应用程序,使用PHP EasyAppns通知推送通知,在Swift 3、iOS 10上运行良好。但有一件事我不明白,为什么TabItem上的徽章在我从通知警报启动应用程序时可以正常工作,但在我直接从应用程序图标(带有红色徽章)打开应用程序时却不能正常工作 下面是我在AppDelegate上使用的代码: func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [String:

我有一个应用程序,使用PHP EasyAppns通知推送通知,在Swift 3、iOS 10上运行良好。但有一件事我不明白,为什么TabItem上的徽章在我从通知警报启动应用程序时可以正常工作,但在我直接从应用程序图标(带有红色徽章)打开应用程序时却不能正常工作

下面是我在AppDelegate上使用的代码:

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [String:Any])
{
    print("Message details \(userInfo)")

    if let aps = userInfo["aps"] as? NSDictionary
    {
        if let alertMessage = aps["alert"] as? String {
            let rootViewController = self.window?.rootViewController as! UITabBarController!
            let tabArray = rootViewController?.tabBar.items as NSArray!
            let tabItem = tabArray?.object(at: 3) as! UITabBarItem
            tabItem.badgeValue = "1"

            let myAlert = UIAlertController(title: "Message", message: alertMessage, preferredStyle: UIAlertControllerStyle.alert)
            let okAction = UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: nil)
            myAlert.addAction(okAction)
            self.window?.rootViewController?.present(myAlert, animated: true, completion: nil)
        }
    }
}
因此,当我点击警报打开我的应用程序时,徽章如下所示:

但当我使用图标本身打开应用程序时,徽章不会显示:

有人知道我做错了什么吗


请让我知道我是否可以改进这个问题

您应该使用
应用程序(uuIdReceiveMemotentification:fetchCompletionHandler:)
方法来处理通知。如文档()中所述,无论应用程序是在前台还是后台,都会调用此方法

同样值得注意的是
应用程序(didReceiveMemotentification:)

如果远程通知到达时应用程序未运行,则 方法启动应用程序并在中提供适当的信息 启动选项字典。应用程序未调用此方法以 处理远程通知


注意,如果应用程序未运行,且用户点击图标,则应用程序将调用
应用程序(uu2;:didfishlaunchingwithoptions:)
。如果应用程序有需要处理的远程通知,则会有相应的launchOption键值对。

不确定这是否与您的问题有关,但您使用的功能已被弃用。您不应该在iOS10中使用此函数。如果成功了,那是因为你很幸运。请参阅和。在iOS10中,如果您希望在用户点击时进行回调,则必须使用我在单击通知时出错,以转到swift 3中的特定视图控制器,错误i:-无法将类型为“UINavigationController”(0x3a79b0a0)的值强制转换为“UITabBarController”(0x3a79b938)应用程序崩溃@lostIn TransitWell,这可能是您代码中的某些内容。您正在获得一个
UINavigationController
,但试图将其用作
uitabarcontroller
。检查您的实现。这可能是另一个问题。它与通知无关。你能帮我处理这个@lostIn Transit吗