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

时间:2021-02-04 07:29:33

标签: ios swift apple-push-notifications silentpush

我将此 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 也在处理这件事。

0 个答案:

没有答案