问题描述
{"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 和 telegram 也在处理这件事。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)