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

Action Required: Apple Push Notification Service Server Certificate Update
Hello Everyone, I have some questions regarding the Apple notification alert update received in October 2024 for the APNs server certificate update. We are using Azure Notification Hub to receive push notifications. I confirmed with the Azure team, and they have already implemented the required changes. However, push notifications are still not working in the sandbox environment. Could you please provide any insights on this? Thanks.
2
0
402
4w
Firebase Notification Fails to Dismiss Voip CallKit UI in Background & Terminated Mode
Hi everyone, I am developing a VoIP calling feature in my Flutter app, using: Agora RTC Engine for real-time calls. CallKit & PushKit (VoIP notifications) for iOS call handling. Firebase Cloud Messaging (FCM) for notifications. Problem: CallKit UI Stays on Screen When Caller Hangs Up (Background/Terminated) I am using Firebase notifications to notify the receiver that the call should be dismissed, but it doesn’t work in the following cases: App is in the background – CallKit UI remains stuck even after receiving the Firebase notification. App is terminated – The Firebase notification does not trigger any background execution, so CallKit UI stays forever. Current Implementation I send an FCM notification to inform the receiver to dismiss CallKit UI. When received in the foreground, it works fine (callEnded method is triggered). But in background or terminated state, the notification is not received or doesn’t execute the code.
1
0
242
4w
NEAppPushProvider Stop not being called after disconnecting from specified SSID
Hello, I have been implementing NEAppPushProvider class to establish my own protocol to directly communicate with our provider server without the need to rely on APNs for background push notifications. I am at a stage where I am able to establish a tcp communicator and receive messages back and forth but I noticed that when I disconnect from the WIFI I've set up by setting a given SSID, I am not getting hit on the Stop method. Below is briefly how I load and save preferences. NEAppPushManager appPushManager = new NEAppPushManager(); appPushManager.LoadFromPreferences((error) => { if (error != null) { Console.WriteLine($"Error loading NEAppPushManager preferences: {error.LocalizedDescription}"); return; } if (!enable) { Console.WriteLine("Disabling Local Push Provider..."); appPushManager.Enabled = false; // ✅ Immediately update UserDefaults before saving preferences userDefaults.SetBool(false, Constants.IsLocalPushEnabled); userDefaults.Synchronize(); appPushManager.SaveToPreferences((saveError) => { if (saveError != null) { Console.WriteLine($"Error disabling Local Push: {saveError.LocalizedDescription}"); } else { Console.WriteLine("Local Push successfully disabled."); } }); return; } // ✅ Now we can safely enable Local Push Console.WriteLine($"Enabling Local Push for SSID: {_currentSSID}"); appPushManager.MatchSsids = new string[] { _currentSSID }; appPushManager.LocalizedDescription = "LocalPushProvider"; appPushManager.ProviderBundleIdentifier = Constants.LocalPushExtensionBundleId; appPushManager.Enabled = true; appPushManager.SaveToPreferences((saveError) => { if (saveError != null) { Console.WriteLine($"Error saving Local Push settings: {saveError.LocalizedDescription}"); } else { Console.WriteLine("✅ Local Push successfully registered."); userDefaults.SetBool(true, Constants.IsLocalPushEnabled); userDefaults.Synchronize(); } }); }); I've read through documentation and was expecting the Stop method to be hit when I turn off Wifi. Am I missing anything? Please let me know if I should provide more info. Currently I just have a console writeline method inside the Stop method to see if it actually gets hit.
1
0
217
4w
Action Required: Apple Push Notification Service Server Certificate Update
Hello Everyone, We have some doubts regarding the apple notification alert update received in Oct 2024 for APNS server certificate update. Does this change is already live for sandbox environment? As we have checked on sandbox environment without changing any certificate its working and we are able to get push notification. Does that means our system does not need any change for production as well? If required where we should add https://www.sectigo.com/knowledge-base/detail/Sectigo-Intermediate-Certificates/kA01N000000rfBO. This certificate. For FYI we are using python library called django-push-notifications which internally call to the APNS server for push notifications.
1
0
505
Feb ’25
Refresh Widget doesn't work from background push notification.
As stated in other posts like: https://developer.apple.com/forums/thread/734488 https://developer.apple.com/forums/thread/652946?answerId=823555022#823555022 Even though the recommended way from Apple documentation is to use push notifications to reload widgets timelines calling WidgetCenter.shared.reloadAllTimelines(), it is unreliable and I couldn't find a pattern of why it works 10% of times and not the other 90%. While the debugger is connected to the App it always works though. My widget needs to reflect updated information otherwise it becomes useless since it display smart home devices states such as the Apple Home widget does as well.
1
1
229
2w
APNS notifications of apns-push-type pushtotalk sometimes stop arriving after switching networks
PLATFORM AND VERSION: iOS Development environment: Other: .net MAUI with vscode Run-time configuration: iOS 18.1.1 DESCRIPTION OF PROBLEM APNS notifications of apns-push-type pushtotalk sometimes stop arriving after switching networks. STEPS TO REPRODUCE We have created a simple app which can be used to deminstrate this issue. When you launch the app it displays the APNS token which you can then use fromn the Apple Push Console to manually send it PTT push notifications. https://github.com/trampster/PttPushNotificationIssue On an iPhone SE (we havn't been able to reproduce on our iPhone 11) Start the APP to register for the APNS push notifications Turn off the WiFi wait for 5 seconds Attempt a push to the app manually using the Push Notifications Console (this should fail, which is fine) Turn on Cellular and wait for it to connect Attempt to push to the app manually using the Push Notifications Console -> This fails, and all attempts to send an pushtotalk push notifications fail until the we switch network again. Send a push while offline before connecting to the new network seems to make it happen more often but hard to tell for sure. The results of the failed push in the console look like this: Delivery LogLast updated: 30/01/25, 16:45:06 GMT+13 Refresh 30 Jan 2025, 16:45:03.661 GMT+13 received by APNS Server 30 Jan 2025, 16:45:03.662 GMT+13 discarded as device was offline The device is actually very much online. Switching networks again oftern makes things come right. But it doesn't seem to come right by itself. We can't respond to network changes and do anything as the whole point of using push-to-talk push notifications is to wake up the app when in the background to answer a call, this means we are not running and therefore cannot respond to network changes to try to work arround this issue.
3
0
317
Feb ’25
Swift program to send Push Notifications
Is there a step by step program on Sending Push notifications? I seem to be stuck at load private key. I get this error. SecKeyCreateWithData failed with error: Error Domain=NSOSStatusErrorDomain Code=-50 "EC private key creation from data failed" It is a new p8 file. I tried different format. I read some articles that say that there is a bug I think. I don't know for sure because it was written in jibberish. 90% of the code is dealing with these stupid keys. This should be 1 function setting the pipe and then I can use the pipe. This is ridiculous. If anybody has any ideas. The code is a mess because I tried so many different ideas. Push Notification.txt
2
0
329
Jan ’25
Apple Push Notification service server certificate
Do we need this new certificate "SHA-2 Root : USERTrust RSA Certification Authority certificate" if we are using token based authentication with APNs? We are signing the JWT with the private Auth key? Or is the new certificate needed on top of this? We are doing something like this: Dictionary<string, object> payload = new Dictionary<string, object>() { { "iss", teamId }, // Apple Developer Team ID { "iat", unixTimestamp } // Issued-at time }; Dictionary<string, object> header = new Dictionary<string, object>() { { "alg", "ES256" }, { "kid", keyId } // Key ID from Apple Developer portal }; string token = JWT.Encode(payload, privateKey, JwsAlgorithm.ES256, header);
4
1
549
Jan ’25
Apns push not working on iphone 13 but works on iphone XR
Hello, I am trying MDM apns push through curl command, the same command works on iphone XR but not on iphone 13, both device iOS version is 17 What can be the cause for this behavior. The command is as below curl.exe -X POST --http2 -k -v --cert PushCert.pem --cacert cacert.pem https://api.push.apple.com/3/device/9BFDFB46D48159D16E5DC80391B765EE99524CF294BB4BF9FB5AEA7A5F3FFD79 -d "{"mdm":"84F0C145-5963-4F06-9D11-DFBDB45802D5"}" -H "apns-topic: com.apple.mgmt.External.c217c1bf-ad51-42a9-9108-2e92ef705b2a" -H "apns-push-type: mdm"
0
0
214
Jan ’25
APNS push working on iphone XR but not on iphone 13
Hello , We are trying MDM APNs push using following command curl.exe -X POST --http2 -k -v --cert PushCert.pem --cacert cacert.pem https://api.push.apple.com/3/device/9BFDFB46D48159D16E5DC80391B765EE99524CF294BB4BF9FB5AEA7A5F3FFD79 -d "{"mdm":"84F0C145-5963-4F06-9D11-DFBDB45802D5"}" -H "apns-topic: com.apple.mgmt.External.c217c1bf-ad51-42a9-9108-2e92ef705b2a" -H "apns-push-type: mdm" The command process correctly there is no error but device doesn't receive the Apns push. At the same time the older device recives the Apns push but newer device not. What can be the cause,how to debug this issue.
1
0
180
Jan ’25
Apple Push Notification service server certificate update
hi i'm testing the new certificate. I'm using the p12 certificate and without doing anything, the sandbox can still be functioned. I assume the new certificate has already been installed in the default path by linux. so I execute openssl s_client -connect 17.188.143.34:443 -servername api.sandbox.push.apple.com -verifyCAfile /etc/pki/tls/certs/ca-bundle.crt -showcerts and i received CONNECTED(00000003) depth=2 C = GB, ST = Greater Manchester, L = Salford, O = Comodo CA Limited, CN = AAA Certificate Services verify return:1 depth=1 CN = Apple Public Server RSA CA 12 - G1, O = Apple Inc., ST = California, C = US verify return:1 depth=0 C = US, ST = California, O = Apple Inc., CN = api.development.push.apple.com verify return:1 --- Certificate chain 0 s:/C=US/ST=California/O=Apple Inc./CN=api.development.push.apple.com i:/CN=Apple Public Server RSA CA 12 - G1/O=Apple Inc./ST=California/C=US -----BEGIN CERTIFICATE----- ... so the server indeed has the certificate, is this correct?
1
0
224
Jan ’25
push notification on capacitor ios app with firebase or apnotic
Hi, I'm working on an IOS app using capacitor. I'm trying to receive push notifications on my downloaded app from testflight. I tried with FCM and it's working on my android app but not on ios and the logs show no error. This is how I retreive the FCM token: const fcmToken = await FCM.getToken() sendSubscriptionToBackEnd({ fcm_token: fcmToken.token, device: platform }) Then I have a job on my backend to send the push notifications: def perform fcm = FCM.new( StringIO.new(Rails.application.credentials.google_application_credentials), Rails.application.credentials.firebase_project_id ) NotificationSubscription.find_each(batch_size: 100) do |subscription| begin response = fcm.send_v1({ token: subscription.fcm_token, notification: { title: 'Un nouveau signal a été publié', body: 'Un nouveau signal a été publié, cliquez ici pour le voir' }, android: { priority: 'high' }, apns: { payload: { aps: { # alert: { # title: 'Un nouveau signal a été publié', # body: 'Un nouveau signal a été publié, cliquez ici pour le voir' # }, sound: 'default' } }, headers: { "apns-priority": "10", "apns-push-type": "alert" } } }) if response[:status_code] == 200 Rails.logger.info "Notification sent successfully to #{subscription.id} on device #{subscription.device}" else Rails.logger.error "Failed to send notification to #{subscription.id} body: #{response[:body]}" # subscription.destroy end rescue StandardError => e Rails.logger.error "Error while sending notification to #{subscription.device}: #{e.message}" subscription.destroy end end end and the logs show that it's successful but i dont receive the notification. When I test from firebase console I receive the push notification on both ios and android capacitor apps. I also added this in the apple delegate: Messaging.messaging().apnsToken = deviceToken Messaging.messaging().token(completion: { (token, error) in if let error = error { NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error) } else if let token = token { NotificationCenter.default.post(name: .capacitorDidRegisterForRemoteNotifications, object: token) } }) } func application(_ application: UIApplication, didFailToRegisterForRemoteNotificationsWithError error: Error) { NotificationCenter.default.post(name: .capacitorDidFailToRegisterForRemoteNotifications, object: error) } I also tried using apns tokens and ther apnotic gem: console.log('APNs Token:', token.value) if (platform === 'ios') { sendSubscriptionToBackEnd({ apns_token: token.value, device: platform }).then(() => { displaySnackbar(`APNs token: ${token.value}`, 'success') }) } }) # Create the APNs connection outside the loop connection = Apnotic::Connection.new( auth_method: :token, cert_path: StringIO.new(Rails.application.credentials.apns_key_path), key_id: Rails.application.credentials.apn_key_id, team_id: Rails.application.credentials.apple_team_id ) NotificationSubscription.find_each(batch_size: 100) do |subscription| if subscription.device == 'ios' begin # Create the notification for the current device token notification = Apnotic::Notification.new(subscription.apns_token) notification.alert = "Un nouveau signal a été publié" notification.topic = Rails.application.credentials.apple_bundle_id # Prepare and send the push push = connection.prepare_push(notification) push.on(:response) do |response| if response.ok? Rails.logger.info "Notification sent successfully to #{subscription.id} on device #{subscription.device}" else Rails.logger.error "Failed to send notification to #{subscription.id} body: #{response.status} - #{response.body}" end end connection.push_async(push) rescue StandardError => e Rails.logger.error "Error while sending notification to #{subscription.device}: #{e.message}" subscription.destroy end end end connection.join(timeout: 5) connection.close end but i have a bad token error: Failed to send notification to 223 body: 400 - {"reason"=>"BadDeviceToken"} I, [2025-01-23T02:23:59.013407 #104] INFO -- : [ActiveJob] [ApnsNotificationJob] I checked my aps entitlement env and its production, have all the certificates, keys.. so I dont understand why i can receive push notifications from firebase console but not from my app
2
0
404
Jan ’25
iOS doesn't handle incoming call of Local PUSH when receiving a Local PUSH after receiving an APNs PUSH
I am developing an application that uses NetworkExtension (Local PUSH function) And VoIP(APNs) PUSH. Nowadays, I found a problem on this app doesn't handle incoming call of Local PUSH when receiving a Local PUSH after receiving an APNs PUSH. My confimation result of my app and server log is below. 11:00 AM: my server(PBX) requests a VoIP(APNs) PUSH notification to the APNs. But my app does not receive the VoIP(APNs) PUSH. At this time, my app is running on LAN (Wi-Fi without internet connection), as a result, NetworkExtension was running. so I think this is normal behaviour. 14:55:11 PM: There is an incoming call from the my server(PBX) via local net, and NetworkExtension calls iOS API(API name is reportIncomingCall). However, iOS does not call the delegate didReceiveIncomingCallWithUserInfo for the reportIncomingCall. 14:55:11 PM: At almost the same time, iOS calls the delegate cdidReceiveIncomingPushWithPayload of VoIP PUSH. (instead of call the delegate didReceiveIncomingCallWithUserInfo for the reportIncomingCall?) And the content of this VoIP(APNs) PUSH was the incoming call at "11:00 AM". In other words, the VoIP(APNs) PUSH at 11:00 AM is stuck inside iOS, and at 14:55:11 PM, from NetworkExtension reports it. I feel there is a problem on iOS doesn't handle incoming call of Local PUSH when receiving a Local PUSH after receiving an VoIP(APNs) PUSH. Would you tell me Apple's opioion about this? If this is known problem, Please tell me about it.
4
0
442
1w
APNs "Discarded - Token Unregistered" showed an upward trend, from millions to tens of millions.
Dear Apple Engineer Recently we found that our push delivery rate has decreased. On the website "https://icloud.developer.apple.com/dashboard/notifications/teams/43Y657P48S/app/com.taobao.fleamarket", we found that starting from January 8, 2025, "Discarded - Token Unregistered" showed an upward trend, from millions to tens of millions. We have not found the reason, and hope you can help us. Team ID: 43Y657P48S Bundle ID: com.taobao.fleamarket Here are some failed tokens, in "Device Token Validator" The query is valid, but the user cannot receive the message: 56025f656cc3aa701898037f59e8d0cb937263ff5585cd1cec9ae661dcc15b19 5fbbd1e604d3662d7583e9377676f8fa276005145278d6dea04b4fc85a7b070e f0970602551f8d249d8f97960a74006ad78688b52fec6b0d19a585 207caff62e 9388fb40209c100afc2db728342f6fe86c7e34787a8fe4a92b73d2503c5286e0 a2819a4708462588b07452ed827d9afb03c343b586e70dcb67a9981f76295704 8949373cd43783fa3e23d38d55ee1fd72475b39f9c2d2fedca3ecb925b094240 Best Regards!
0
0
142
Jan ’25
Apple Push Notification service's Certification Authority (CA) update
As you announced at this link https://developer.apple.com/forums/thread/766788, 'APNs will update the server certificates in sandbox on January 20, 2025, and in production on February 24, 2025.' I guess you have updated the sandbox certificate. What can we do to test whether we have correctly updated our application’s Trust Store to include the new server certificate.We test on a server that haven't updated the new server certificate, connect your sandbox environment 'api.sandbox.push.apple.com' to send notifications, it succeed. As I guess, it should failed.
2
0
496
Jan ’25
Apple Push Notification service server certificate Was the update published as scheduled?
I tried below at 2:00 PM on 21/01/2025(JST). Apple Push Notification service server certificate update I followed above, a new server certificate: "SHA-2 Root : USERTrust RSA Certification Authority certificate" was added to my push server, but a certificate error occurred and push notifications could not be sent. So I refered this article,Instead of connecting via DNS name resolution at api.development.push.apple.com, I fixed api.development.push.apple.com to "17.188.143.34" in /etc/hosts, I could push notifications with the new server certificate. (I got this IP(17.188.143.34) from this airtcle) From this, I suspect that Apple had not yet updated the APNs certificate (CA) for the Sandbox environment as of 2:00 PM on January 21, 2025 (JST). Was the update published as scheduled?
1
0
577
Jan ’25
"InvalidProviderToken" with APN push service when using code-generated token
Problem We have successfully set up push notifications using Apple APN service, that is push notifications work when using a token generated using the JSON Web Token Generator in the Push Notification console. However, we get an "InvalidProviderToken" error when creating using our own token using the following code. The Key and TeamID is definitely correct (obviously, censored in the below code). When pasting our token in the JSON Web Token Validator in the Push Notification console we get the error „Invalid signing key“. We merely pasted our secret key in our setNewTokenIfNeeded code, separated on four lines using the “““ style. Does anyone know why this error happens? Given that it works when we upload our .p8 file to the JSON Web Token Generator and we simply paste the text of this file (excluding the lines with "-----BEGIN/END PRIVATE KEY-----") I guess our secret key is correct? Code to generate token fileprivate var currentToken: String? fileprivate var currentTokenCreateTime: Date? fileprivate func setNewTokenIfNeeded() { // Ensure, token is at least 20 minutes but at most 60 minutes old if let currentTokenCreateTime = currentTokenCreateTime { let ageOfTokenInSeconds = abs(Int(currentTokenCreateTime.timeIntervalSinceNow)) NSLog("Age of token: \(Int(ageOfTokenInSeconds / 60)) minutes.") if ageOfTokenInSeconds <= 20 * 60 { return } } // Generate new token NSLog("Renewing token.") let secret = """ ABCABCABCABCABCABCABCABCABCABCABCABC+ABCABC+ABCABCABC+ABCABCAB/+ ABCABCABCABCABCABCABCABCABCABCABCABC+ABCABC+ABCABCABC+ABCABCAB/+ ABCABCABCABCABCABCABCABCABCABCABCABC+ABCABC+ABCABCABC+ABCABCAB/+ ABCABCAB """ let privateKey = SymmetricKey(data: Data(secret.utf8)) let headerJSONData = try! JSONEncoder().encode(Header()) let headerBase64String = headerJSONData.urlSafeBase64EncodedString() let payloadJSONData = try! JSONEncoder().encode(Payload()) let payloadBase64String = payloadJSONData.urlSafeBase64EncodedString() let toSign = Data((headerBase64String + "." + payloadBase64String).utf8) let signature = HMAC<SHA256>.authenticationCode(for: toSign, using: privateKey) let signatureBase64String = Data(signature).urlSafeBase64EncodedString() let token = [headerBase64String, payloadBase64String, signatureBase64String].joined(separator: ".") currentToken = token currentTokenCreateTime = Date() } fileprivate struct Header: Encodable { let alg = "ES256" let kid: String = "ABCABCABC" // Key (censored here) } fileprivate struct Payload: Encodable { let iss: String = "ABCABCABC" // Team-ID (censored here) let iat: Int = Int(Date().timeIntervalSince1970) } extension Data { func urlSafeBase64EncodedString() -> String { return base64EncodedString() .replacingOccurrences(of: "+", with: "-") .replacingOccurrences(of: "/", with: "_") .replacingOccurrences(of: "=", with: "") } } Code to send the push notification func SendPushNotification(category: ConversationCategory, conversationID: UUID, title: String, subTitle: String?, body: String, devicesToSendTo: [String]) { // Für alle Felder s. https://developer.apple.com/documentation/usernotifications/generating-a-remote-notification let payload = [ "aps": [ "alert": [ "title": title, "subtitle" : subTitle ?? "", "body": body ], "category" : category.rawValue, "mutable-content": 1 ], "conversationID": conversationID.uuidString ] as [String : Any] // Ggf. Token setzen setNewTokenIfNeeded() guard let currentToken = currentToken else { NSLog("Token not initialized.") return } NSLog(currentToken) // Notification an alle angegebenen Devices schicken let bundleID = "com.TEAMID.APPNAME" for curDeviceID in devicesToSendTo { NSLog("Sending push notification to device with ID \(curDeviceID).") let apnServerURL = "https://api.sandbox.push.apple.com:443/3/device/\(curDeviceID)" var request = URLRequest(url: URL(string: apnServerURL)!) request.httpMethod = "POST" request.allHTTPHeaderFields = [ "authorization": "bearer " + currentToken, "apns-id": UUID().uuidString, "apns-topic": bundleID, "apns-priority": "10", "apns-expiration": "0" ] request.httpBody = try! JSONSerialization.data(withJSONObject: payload, options: .prettyPrinted) URLSession(configuration: .ephemeral).dataTask(with: request) { data, response, error in if let error = error { NSLog(error.localizedDescription) } if let data = data { NSLog(String(data: data, encoding: .utf8)!) } }.resume() } } On a similar note, some people seem to encounter this error when using the prettyPrinted option for the JSON serialization (i.e., in request.httpBody = try! JSONSerialization.data(withJSONObject: payload, options: .prettyPrinted). Could this be the culprit, given our secret key contains „/„ and „+“? Many thanks!
0
0
280
Jan ’25