微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

一段时间后,静默推送通知不会触发“didReceiveRemoteNotification”?

如何解决一段时间后,静默推送通知不会触发“didReceiveRemoteNotification”?

我将此 apns 负载用于静推送通知

{"aps":{"alert":"","badge":10,"content-available":1,"title":"Umer","message":"Hi umer...","id":"1","notification-type":"Text","apns-priority":"10","apns-push-type":"alert"}}

此有效载荷已设置为使通知的优先级为最高。现在在此有效载荷的帮助下,我可以在前台后台和应用程序被杀死的所有时间接收通知,但是一旦应用程序被杀死并且其他一些应用程序在前台打开。我只能在一段时间内接收通知,此后虽然有效载荷中的徽章值正在使用应用程序的徽章进行更新,但在“didReceiveRemoteNotification”委托中编写/实现的代码没有得到点击,或者我们可以说通知没有触发“ didReceiveRemoteNotification”委托。

这就是我在 AppDelegate 中所做的

func application(_ application: UIApplication,didReceiveRemoteNotification userInfo: [AnyHashable : Any],fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void){
    
    debugPrint(userInfo)
    debugPrint("slient notification recieved")
    let notificationData = userInfo["aps"] as? [String:Any]
    let title = notificationData?["title"] as? String
    let message = notificationData?["message"] as? String
    let notificationType = notificationData?["notification-type"] as? String
    let id = notificationData?["id"] as? String
    debugPrint(id ?? "no id")
    
    if UIApplication.shared.applicationState == .active {
        GenericCallManager.shared.sendNotification(sendername: title ?? "Mood",SenderMsg: message ?? "message",notificationtype: notificationType ?? "md_chat_type")
    }
    
    
   let contactModel = ContactModel(contactName: "+" + "97412345678",contactNumber: "97412345678",ghostName: "",ghostPhoneNo: "",contactJID: id ?? "",profileId: "",subscribeState: false,blockedState: false,saveState: false,contactStatus: 1,rowId: "",userAvtar: "",userCustomProfileImageUrl: "",userProfileDescription:"",profileImageUrl: "",userImageHashKey: "",userImageBase64String: "",password: "",isfromguest: false,is_mute: false,mute_time: "",is_group: false,disable_presence_to_roster: false,disable_presence_time: "",recivedProfileIamge: "",drafftedMessage: "",draftedMessageType: "",userThumbnailImage: "",isBurningEnabled : false,burnEnabledTime : "",burnTime : "",notmymood_time: "")
    
    var dbaccessLayerObject: DbLayerMessageProtocole?
    dbaccessLayerObject = dbaccessLayer()
    dbaccessLayerObject?.appendEntryForContact(contactModel: contactModel)
    
    let currentCount = UserDefaults.standard.integer(forKey: ExtensionGlobal.BadgeCount)
    UIApplication.shared.applicationIconBadgeNumber = currentCount + 1
    UserDefaults.standard.setValue(currentCount + 1,forKey: ExtensionGlobal.BadgeCount)
    
    completionHandler(UIBackgroundFetchResult.newData)
    
    
}

有可能,WhatsApptelegram 也在处理这件事。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。