1

我正在使用此 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)
    
    
}

有可能,WhatsApp电报也在处理这件事。

4

0 回答 0