Send push notifications to Mac, iOS, iPadOS, tvOS devices through your app using the Apple Push Notifications service (APNs).

Posts under APNS tag

200 Posts
Sort by:

Post

Replies

Boosts

Views

Activity

Push Notifications are not delivered to a good percentage of users
Hi all, In the app I developed for iOS I am using Firebase SDK (cloud messaging FCM) to provide the topic feature to deliver notification to thousands subscribed iOS users. I know FCM does not directly deliver the notifications to the final users and this is just an intermediary that formats the notification in way the APNs can understand client by client (using the APN device tokens) and this service (APNs) is in charge of delivering the notifications to the final users. The notifications are sent from a linux server through a cURL request to FCM. One example of silent notification that is like a heartbeat is below: !/bin/sh notifID=`date +"%Y%j"` value=`date -u "+%s.%N"` curl -H "Content-type: application/json" \ -H "Authorization:key=XXXXXXSECRETXXXXXX" \ -X POST -d '{ "to": "/topics/ioschannel","content_available":true,"data":{"notificationType":"silentNotification","silentNotificationId":"'$notifID'","senttime":'$value'},"priority":"high","headers":{"apns-priority":"10"},"time_to_live":60}' \ https://fcm.googleapis.com/fcm/send In the below image you can see some statistics provided by the metrics in the Apple Push Notification Console. We currently have almost 5.5k users who have mainly installed the app on their iPhones. As you can notice the APNs received a bit more than 5k notifications but what it is remarkable is the fact that only about 70% of the users receive the notification on their devices. Few notifications are on the APNs storage and delivered later on. Some devices can be offline and others are can be on power save mode but I don't understand why so many users are not receiving the notification (this particular notification is sent at 5 pm local time). Aside from the example silent notification I send other notifications to be processed in the background in the app in order to evaluate and decide to present or not a notification on the notification bar with a sound. The situation is the same, almost the same percentage don't receive the notification and almost 70% receive them on time. I have another app in Android and I don't have this problem. More than 90% of the users receive the notifications. What it is really interesting about Android is that the user can provide the permission to remove the app from the battery optimization. This is really important permission because the Android OS provides resources (network and giving priority to received push notifications) and even in power save mode the notifications are delivered. If I go straight from our linux server to APNs this situation won't change because APNs cannot deliver the notifications. Why is this happening? Is there any way to provide a permission to the app to have the highest priority? Any advice, feedback or hint will be really appreciated.
0
1
315
Jan ’24
[APNS][RemoteNotifications] didReceiveRemoteNotification UIBackgroundFetchResult method doesn't being called, when App is in background state, iOS swift push notification.
Hello Friends, Could you please help me, whats wrong. We have requirement that, when I receive remote notifications on device, I need to save it in to db (without tapping or opening notification banner), regardless my app is in Foreground or in Background. I receive remote notifications on device & simulator both. And UNUserNotificationCenter delegates are being called if app is in foreground, but didReceiveRemoteNotification is not calling when app is background, not killed. func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { // Save to DB completionHandler(.newData) } I am having Xcode 15.2 & I tried on iOS versions 16.x & 17.x both on Simulator and on real devices. // Added this code in App delegate UNUserNotificationCenter.current().delegate = self UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in if granted { // User granted permission DispatchQueue.main.async { UIApplication.shared.registerForRemoteNotifications() } } else { // User denied permission } }
2
0
751
Jan ’24
Need Assistance: Unintended 'webServiceURL' Callback Triggered for All Apple Passes
I have successfully created an Apple Pass wallet with a 'webServiceURL' using PHP. The pass is added to the Apple Wallet successfully. However, when I sent a push notification to update a specific pass using its serial number, it worked as expected initially. However, in the last few days, Apple has been triggering the 'webServiceURL' callback for all passes, when we trigger a push for one pass/deviceID. I'm unsure how to prevent this callback from Apple. Please provide assistance on resolving this issue.
0
0
336
Jan ’24
Handle background notification in terminated status app
i have an issue when handling silent push in my app when the user close the app, here is my native code which works like charm when the app in the foreground, background or terminated status from a short time from closing the app, and after long time from closing it (+30min) it will not work anymore, it make me confuse why it does not work and other messaging app like viber, whatsapp and messanger you can still receive messages and calls even you swipe the app and close it !! is there any thing must i add !! override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { Messaging.messaging().appDidReceiveMessage(userInfo) if Auth.auth().canHandleNotification(userInfo) { completionHandler(.noData) return } // sample notification for testing let content = UNMutableNotificationContent() content.title = "Hi there" content.body = "Just test" content.sound = UNNotificationSound.default let request = UNNotificationRequest(identifier: "helloNotification", content: content, trigger: nil) UNUserNotificationCenter.current().add(request) { (error) in if let error = error { print("Error adding notification request: \(error.localizedDescription)") } } // resent to dart side let controller: FlutterViewController = window?.rootViewController as! FlutterViewController let notificationChannel = FlutterMethodChannel(name: "notificationHandler", binaryMessenger: controller.binaryMessenger) var dataToSend: [String: Any] = [:] if let text = userInfo["text"] as? String { dataToSend["text"] = text } // Convert the dictionary to NSDictionary let nsDataToSend = NSDictionary(dictionary: dataToSend) // Pass the NSDictionary to Dart notificationChannel.invokeMethod("handleRemoteMessage", arguments: nsDataToSend) } i checked : background capabilities : remote notifs, background fetching, voip, background processing
1
0
1k
Jan ’24
Persistent Issue with Push Notifications on iPhone Devices
I understand that you are facing an issue with push notifications not being delivered to iPhone devices in your app since January 12, 2024, at 4:05 AM (Japan time). You've confirmed that the APNS authentication key is still valid, and the key itself is correct. Additionally, you mentioned that push notifications are working fine on the sending device. Despite resetting the authentication key, the problem persists, and you haven't received a specific error code; instead, you are getting a general error message. To troubleshoot and resolve this issue, you may want to consider the following steps: Check for Apple Server Status: Ensure that Apple's push notification servers are operational. Sometimes, server outages on Apple's end can affect push notification delivery. Review Apple Developer Console: Double-check the Apple Developer Console for any relevant messages or issues related to your app and push notifications. It might provide additional insights into the problem. Check Device Settings: Confirm that the affected iPhone devices have proper network connectivity and are not in a "Do Not Disturb" mode. Also, ensure that the app's notification settings on the user's device are configured correctly. Review Payload and Certificate: Examine the payload of your push notifications and ensure that it complies with Apple's guidelines. Additionally, verify that your app's push notification certificate is still valid. Update to the Latest SDK: Make sure that you are using the latest version of the SDK provided by Apple for handling push notifications. Contact Apple Developer Support: If the issue persists, consider reaching out to Apple Developer Support for further assistance. They may be able to provide specific insights into the problem and guide you through the resolution process. Implement Logging: Introduce logging mechanisms in your app to capture more detailed information about the push notification process. This can help you pinpoint the exact stage where the issue occurs. Network Firewall and Proxy: Check if there are any network firewalls or proxies that might be blocking the communication between your server and Apple's push notification servers. Remember to document any additional information or error messages you receive during the troubleshooting process, as these details will be helpful when seeking assistance from Apple or other developer communities. If the problem persists, seeking professional assistance or consulting with Apple's technical support may be necessary. 【Message content】 Auth error from APNS or web push Service
0
0
585
Jan ’24
SIP Client app - Push notification unavailable
Hello Team, We have developed an SIP Client application, where the connection is through SIP Server. We are unable to handle incoming calls when app is in the background. The local servers are blocked by firewall due to which the push notification is unavailable and is only available via VPN connection. Requesting you to please guide us on how we can receive incoming calls without push notification. We also would like to know how we can receive incoming calls when the app is completely terminated or closed from background and how to auto-start the app to receive incoming calls.
2
0
492
Jan ’24
NotificationService is not called
I have read through many forums but haven't found a solution for myself. When sending a notification, my NotificationService is not being called. I added it exactly as described in the official Apple tutorial and tried adding it again following other tutorials. Nothing helped. I haven't made any changes to it; it is in the same form as it is automatically created. Here it is: import UserNotifications class NotificationService: UNNotificationServiceExtension { var contentHandler: ((UNNotificationContent) -> Void)? var bestAttemptContent: UNMutableNotificationContent? override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) { self.contentHandler = contentHandler bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent) if let bestAttemptContent = bestAttemptContent { // Modify the notification content here... bestAttemptContent.title = "\(bestAttemptContent.title) [modified]" contentHandler(bestAttemptContent) } } override func serviceExtensionTimeWillExpire() { // Called just before the extension will be terminated by the system. // Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used. if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent { contentHandler(bestAttemptContent) } } } It does not print anything or hit any breakpoints. The notification payload looks like this: { "Simulator Target Bundle": "my.bundle", "aps": { "alert": { "title": "Its title", "body": "Very nice text" }, "sound": "default", "category": "CustomSamplePush", "mutable-content": 1 } } Things I've tried: Ensured the minimum version matches that of the application. Configured info.plist, including UNNotificationExtensionCategory. Ensured "Copy Only When Installed" is unchecked. The Content extension works. However, prints and breakpoints are also not working.
1
0
638
Jan ’24
Periodic Background Update (including force-quit)
As the title says. We have a pretty specific need for our app, and I have an idea of how to achieve it, but would like input on whether it's good practice or not. In communication apps such as Whatsapp or Discord, they need to send local notifications (and ideally update cached message data so it's fresh) anytime the user gets a new message. Conveniently for them, they control the backend, and so can just send out a silent push notification to the device(s) of user involved. In our case, we are creating a UI for someone else's backend, meaning we can't simply send a silent push on data change. What we were originally thinking was a sort of crowd-source involving a combination of silent push and background refresh, but refresh won't work if the user closes the app. I've read all the given reasons for this, and though I still disagree, there isn't anything we can do about it. So what I'm now thinking is that, at whatever interval (say 1-3hrs) some serverless function sends a silent push to every single client, which will wake them up to make a fetch and compare to the cached data and send a local notification if necessary. Downside here is it will likely incur some cost, and frankly it just feels kind of iffy as a solution, but I'm not sure what else we can do without controlling the backend API. Thoughts? Is there anything I'm missing? Any better ideas? Thanks in advance!
2
0
419
Jan ’24
App Transfer's effect on Push Notifications
I'm in the process of preparing to receive an iOS App transferred from a 3rd party developer. It's unclear from the transfer documentation whether Push Notifications will continue to work after the transfer is complete. Could anyone provide clarity on when push notifications would begin to fail, if at all? For instance, immediately at transfer, after the first release from the new app store, or no failure until new APN tokens are created? https://developer.apple.com/help/app-store-connect/transfer-an-app/overview-of-app-transfer/
1
0
473
Jan ’24
High "Discarded - Disabled" metrics for Location Notifications
Hi everyone, I've run into an issue with push notifications in our app, specifically those related to the location push service extension. In the Push Notifications Console, there's a high number of notifications marked as “Discarded - Disabled” under Location Notifications. I'm trying to figure out what's causing this. We are seeing thousands of “Discarded - Disabled” for location but the other push types are being discarded in much smaller numbers (in the tens). Here's what I need help with: What do the different 'Discarded' categories mean in push notifications? Which are normal and which are red flags? Why are so many Location Notifications being discarded as 'Disabled'? Is this a common device setting issue? Any tips on reducing these discarded notifications, especially for location-based services? Would really appreciate your insights or any pointers towards relevant resources! Thanks! LC
0
0
266
Jan ’24
APNS Key Vs Certificate Security
I've learned that providing an APNS “Key (Cannot expire)” instead of an APNS “Certificate (Can expire)” will provide the app "access to all topics" for all apps within the organization ‘team’ that the key is forged from. 1.) Can someone elaborate on the specifics for what that means from a security prospective? For instance, if my organization 'team' manages many applications under the same umbrella account and provides the same (or different) APNS key to each app, but one of the apps accidentally (or intentionally) wants to utilize the APNS key to affect the other apps, what are the potential consequences? And, is it possible to create a new APNS key for each app to close any security concerns for multiple apps managed under the same account, or are we stuck with every key having access to all topics?
1
1
1.1k
Jan ’24
Notification Service Extension usage time
Hello all. I noticed, that NSE living more than 30 seconds ( that described in doc ). When app receive notification, it created process NSE, and send notification to didReceive function, after this, app have 30 seconds to call contentHandler closure, after contentHandler is called, I expected that NSE process is killed, but it's not. If app using singletons in NSE, they won't dealloc after contentHandler is called, so, after new notification received, singletons still alive. Does it legal to not drop connection to websocket after contentHandler closure get called? For example, notification received, NSE process is loaded, websocket manager signleton is initialzied and started session, after few seconds contentHandler closure get called, so, system won't kill NSE because of 30 seconds timer, and my web socket connection will alive so long as possible, so, I not need to open it each 30 seconds, is that legal or not?)
3
0
529
Jan ’24
APNs Pushes Failing, Device is "offline" when it's not
Hi - I'm having issuses with pushing notifications both locally and from a server to either my phone or the simulator. KEEP IN MIND I had previously had them working not an hour ago, and for some reason, after changing no code i come back to errors upon errors. I am using 17.0.2 and xcode. Here are some things i've tried: CloudKit's Push notification console - one day it just suddenly stopped working, and doing pushes that previously had worked suddenly gave the vague and very unhelpful error message "device was offline." I know my credentials and device token are all valid because it doesn't throw any other errors regarding that. AWS Pinpoint/SNS - i previously had it working sending push notifications from SNS. I get a 200 response, but it still doesn't show a push notification. I think Apple is misinterpreting "discarded as device was offline" somehow as a success? .apns drag-n-drop - i literally sometimes fail dragging and dropping into the simulator a properly configured .apns file to trigger a notification. Sometimes it works, sometimes it doesn't. The literal only thing i changed was adding the target of the user notifications extension (so i can add custom actions on a notification). Unless that target somehow broke everything, Apple seems to think my device is offline. Hopefully someone might have been experiencing this and can understand my fury.
2
0
1.3k
Jan ’24