iOS 推送通知 - 角标(Badge)不会显示

标签 ios iphone swift push-notification apple-push-notifications

如果我收到通知,则不会显示角标(Badge)。

这是我注册通知的位置(如您所见,选择了角标(Badge)):

    if #available(iOS 10.0, *) {
        UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { (granted, error) in
            if error == nil {

                if granted {
                    print("granted")

                    DispatchQueue.main.async {
                        UIApplication.shared.registerForRemoteNotifications()
                        UNUserNotificationCenter.current().delegate = self
                    }
                } else {
                    print("not granted")
                }
            }
        }
    } else {
        let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [UIUserNotificationType.badge, UIUserNotificationType.sound, UIUserNotificationType.alert], categories: nil)
        UIApplication.shared.registerForRemoteNotifications()
        UIApplication.shared.registerUserNotificationSettings(settings)
    }

这是我的有效负载:

                notificationJsonPayload =
                    "{\"aps\" : " +
                    " {" +
                    " \"alert\": \"$(Message)\"," +
                    " \"badge\": 1" +
                    " }" +
                    "}";

通知显示在顶部,但应用程序图标上没有任何角标(Badge)。

最佳答案

您还需要设置应用程序角标(Badge) -

UIApplication.shared.applicationIconBadgeNumber = "your badge number from response "

当角标(Badge)编号为0时,该角标(Badge)将被隐藏。

关于iOS 推送通知 - 角标(Badge)不会显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49557635/

相关文章:

iphone - iOS 使用 GL_RGBA8

ios - 应用程序打开启动屏幕但崩溃(在 iOS 设备上)

ios - 滚动父 View 的 CollectionView 以在模式关闭之前显示单元格

iphone - 逐帧播放视频

ios - 是否可以使用 Alamofire swift 在 api 命中时将数组和字典都发送到参数中?

ios - 无法导入桥接头

android - HTML5 应用程序和原生资源

iphone - 使用 UITableView 和 paging.enabled=YES(或其他方式?)设置页面大小

swift - 使用随机值 Swift 从 JSON 加载特定数据

.net - 在 monotouch 中使用 .net dll 时找不到 DLL