我需要幫助完成這段代碼,以便在收到推送通知時應用會顯示徽章號碼,我可以收到推送通知,但只有應用上沒有徽章,這裏是代碼如何在收到推送通知時更新徽章號碼
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any],
fetchCompletionHandler completionHandler: @escaping
(UIBackgroundFetchResult) -> Void) {
if let aps = userInfo["aps"] as? NSDictionary, let _ = aps["alert"] as? String, let sound = aps["sound"] as? String
{
if let systemSound = SystemSoundID(sound) {
AudioServicesPlayAlertSound(systemSound)
}
NotificationCenter.default.post(name: Notification.Name(rawValue: SystemSetting.refreshCouponListNotification), object: nil)
completionHandler(UIBackgroundFetchResult.newData)
}
}
您可以按照本教程https://eladnava.com/send-push-notifications-to-ios-devices-using-xcode-8-and-swift- 3 /和https://stackoverflow.com/questions/44490391/swift-3-turn-off-badge-alert-sound – iPatel