1

I'm using this apns payload for silent push notifications

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

this payload has been set so as to make notification's priority HIGHEST.Now with help of this payload, I'm able to recieve notifications in all the time in foreground, background and app being killed but once the app is being killed and some other apps are opened in foreground. I'm only able to receive notifications for some time and after that although badge value coming in payload is getting updated with app's badge but code written/implemented inside "didReceiveRemoteNotification" delegate does not getting hits or we can say that notification is not triggering "didReceiveRemoteNotification" delegate.

This is what I'm doing inside 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)
    
    
}

It's possible, WhatsApp and telegram are also handling this thing.

James Z
  • 12,209
  • 10
  • 24
  • 44
umer farooqi
  • 552
  • 2
  • 8

0 Answers0