Notifications

RSS for tag

Learn about the technical aspects of notification delivery on device, including notification types, priorities, and notification center management.

Notifications Documentation

Post

Replies

Boosts

Views

Activity

APNS Push sent via custom server using Certificate-based authentication not arriving
I have been trying to implement APNS Push Notifications into the iOS App I'm currently developing, and I'm having issues with notifications sent via my custom server not being delivered. I have built and ran the App on my device (iPhone running iOS 17.6.1), requested permission for notifications from UNUserNotificationCenter, and saved the device token for testing purposes. As a sanity check for the device token and the App entitlements, I used the CloudKit tool for testing Push Notifications. The notifications I send aimed at the "DEVELOPMENT" Environment work properly and arrive on the device. To configure my custom server, I created the Sandbox Apple Push Notifications certificate in my Developer portal, installed it on my Mac, exported the certificate and key together into a .p12 file, and created the PEM file using this command: openssl pkcs12 -in Certificates.p12 -out sandbox.pem -nodes -clcerts When my server attempts to send a notification, it appears to connect to the server and send the payload, but the notification never arrives on the device. I don't get any errors when my server writes the notification's binary payload to the connection. For clarity, here is the code from my server that sends the "aps" payload to APNS (written in PHP): public function sendPushNotification($deviceToken, $title, $message) { $jsonPayload = $this->composePayload($title, $message); $msg = $this->buildBinaryNotification($jsonPayload, $deviceToken); $this->connectToApns(); $result = fwrite($this->mApnsConnectionHandle, $msg, strlen($msg)); if (!$result) { $this->writeToLog("Message not delivered?!"); } else { $this->writeToLog("Message successfully delivered!"); } $this->disconnectFromApns(); } And this is the code for constructing the JSON payload, and for converting that JSON into a binary string: private function composePayload($title, $message) { // Create the payload body $body['aps'] = array( 'alert' => array( 'title'=>$title, 'body'=>$message ) ); // Encode the payload as JSON $payload = json_encode($body); return $payload; } private function buildBinaryNotification($payload, $deviceToken) { if (strlen($payload) > 0 && strlen($deviceToken) > 0) { $msg = chr(0) . pack('n', strlen($deviceToken)) . pack('H*', $deviceToken) . chr(0) . pack('n', strlen($payload)) . $payload; } return $msg; } Any suggestions or advice would be appreciated.
1
0
293
Sep ’24
VoIP Not Working Background
Hello, I have an app which I have enabled VoIP entitlement and implemented all the CallKit and PushKit registries and delegates. I can successfully get a VoIP token. I can successfully send VoIP push notifications (and receive them via the PushKit delegate function) and then report an incoming call via CallKit, but only while my app is in the foreground. I have checked the entitlement in XCode and the Info.plist directly, and they both (as expected) show voip as a background mode. The VoIP notification is being sent via AWS SNS and everything works while the app is in the foreground. I cannot understand why the app is not waking up while in the background. This is the VoIP notification sent via SNS: aps: { alert: "Intercom call", "content-available": 1 } SNS Message Attributes: 'AWS.SNS.MOBILE.APNS.TOPIC': { DataType: 'String', StringValue: `${bundleId}` }, 'AWS.SNS.MOBILE.APNS.PUSH_TYPE': { DataType: 'String', StringValue: 'voip' }, 'AWS.SNS.MOBILE.APNS_VOIP.TTL': { DataType: 'String', StringValue: '0' }, 'AWS.SNS.MOBILE.APNS_VOIP_SANDBOX.TTL': { DataType: 'String', StringValue: '0' }, 'AWS.SNS.MOBILE.APNS.PRIORITY': { DataType: 'String', StringValue: '10' } As I say, func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) async works correctly when in the foreground. I cannot see any reason why it would not work from the background. I am also receiving normal remote notifications correctly foreground and background.
2
0
340
Sep ’24
Understanding Time Sensitive Notifications for macOS?
I've seen a fair amount of resourcing for iOS notifications, but on macOS there is little if any documentation on what we're supposed to experience when using time-sensitive notifications. We are intending to send time-sensitive notifications about IDP credentials from our agent to the end user, with the intention of breaking through Do Not Disturb or Focus modes. What should we expect the experience to be? We've implemented the notifications, but on macOS, they do not break through focus or DND the way that we'd expect them to.
1
1
220
Sep ’24
Critical Alert Sound Fades In Instead of Playing at Full Volume on iOS
I’m currently developing an iOS app that includes critical alerts as part of our notification system. We’ve noticed an issue where, on some occasions, the critical alert sound fades in rather than playing immediately at full volume. Behavior: When a critical alert is triggered, the notification sound sometimes fades in gradually, instead of starting at the desired volume level right away. This doesn’t happen every time, but it’s frequent enough to be concerning. Has anyone else encountered this issue, or does anyone have insights into why this might be happening? We’re looking for advice on how to ensure the sound plays correctly every time a critical alert is triggered.
2
0
262
Aug ’24
Is there a case that the same device token can be detected from different IDFVs?
An incident occurred in which the same device token was sent from different IDFVs. To investigate the cause, please let me know the informations below. ・What are the conditions under which the IDFV changes? ・When an IDFV changes due to uninstallation, etc., does the device token always change? ・Is there a chance that a device token that has been used in the past in another terminal will be used in another IDFV terminal?
1
0
329
Aug ’24
Invalid iss (issuer) from APNS p8 device
I have generated a key for APNS push notification in a newly created Apple account. However if I check the certificate with the Apple tool https://icloud.developer.apple.com/dashboard/notifications/ it displays "invalid iss (issuer)" (If I want to use it, I get a 403 error ("InvalidProviderToken"), that is logical) (it works fine on other account with the working generated key) Any idea to understand the issue ?
3
0
235
Aug ’24
Is the Communication Notifications capability required for a Notification Service Extension and a Notification Content Extension?
I would like to add both a Notification Service Extension and a Notification Content Extension to my application. After reading some documentation and tutorials etc. I'm not clear if the Communication Notifications capability is needed or not. If it is, should it get added to the App ID or the notification IDs, or both?
1
0
341
Aug ’24
Why is willPresentNotification called twice here?
Please find below a complete app example. It has a button, when you press it, a local notification is created. However, the UnNotificationCenter.delegate is called twice, and I can't understand why. I am trying to move my project from Objective-C to Swift, and my similar code there doesn't get called twice, so I'm confused. Can anybody shine a light on this? Pointers appreciated. App: @main struct NotifTestApp: App { init() { UNUserNotificationCenter.current().delegate = NotificationReceiveHandler.shared configureUserNotifications() } var body: some Scene { WindowGroup { ContentView() } } private func configureUserNotifications() { UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { granted, error in if granted { print("Notification permission granted.") } else if let error = error { print("Error requesting notification permissions: \(error)") } } } } class NotificationReceiveHandler: NSObject, UNUserNotificationCenterDelegate { static let shared = NotificationReceiveHandler() //>> THIS IS CALLED TWICE WHEN I PRESS THE BUTTON func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { NSLog(">>> Will present notification!") completionHandler([.sound]) } } ///THE UI struct ContentView: View { var body: some View { VStack { Text("👾") .imageScale(.large) .foregroundStyle(.tint) Text("Notification test!") Text("When i press the button, will present is called twice!!").font(.footnote) .padding(10) Button("Create Notification") { createNotification( message: "This is a test notification", header: "Test Notification", category: "TEST_CATEGORY", playSound: true, dictionary: nil, imageName: nil) } .padding() .background(Color.blue) .foregroundColor(.white) .cornerRadius(8) } .padding() } } #Preview { ContentView() } private func createNotification(message: String, header: String, category: String, playSound: Bool = true, dictionary: NSDictionary? = nil, imageName: String? = nil) { let content = UNMutableNotificationContent() content.title = header content.body = message content.categoryIdentifier = category content.badge = NSNumber(value: 0) if let imageName = imageName, let imageURL = Bundle.main.url(forResource: imageName, withExtension: "png") { do { let attachment = try UNNotificationAttachment(identifier: "image", url: imageURL, options: nil) content.attachments = [attachment] } catch { print("Error creating notification attachment: \(error)") } } content.sound = playSound ? UNNotificationSound(named: UNNotificationSoundName("event.aiff")) : nil if let infoDict = dictionary { content.userInfo = infoDict as! [AnyHashable: Any] } let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil) UNUserNotificationCenter.current().add(request, withCompletionHandler: nil) }
8
3
1.3k
Aug ’24
There are some difference between Push Notifications Platform 's statue result and doc
in Push Notifications Platform : when i test the device remove our app , the status result is “- discarded as device was offline” when i test close the notification auth in our app, the status result is “- stored for device power considerations" but i saw the flow in doc , I didn't directly saw that these two states are like this https://developer.apple.com/documentation/usernotifications/viewing-the-status-of-push-notifications-using-metrics-and-apns how can i know the directly status in this two cases ?
0
0
304
Aug ’24
iOS 18 when app in foreground the notiification will prensent twice
Hi. all Now we test our app in iOS18. When app in foreground mode, the app will present our alert controller twice.We used the follow test(send local notification): UNUserNotificationCenter.current().add(request, withCompletionHandler: { (error) in if error == nil { print("") } }) also have same issue. Debug code, we found the below method have been called by system twice. (void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void (^)(UNNotificationPresentationOptions options))completionHandler API_AVAILABLE(macos(10.14), ios(10.0), watchos(3.0), tvos(10.0)); Anyone have the same issue? Do you have any idea? Thank you .
6
3
2.0k
Aug ’24
APNS traffic not honoring the routing table?
I was seeing APNS traffic not honor the networking routing table and instead forced onto a specific interface starting in the beta releases of macOS Sequoia. I wanted to ask here to see if it was by design. Were there any release notes or communication in regards to this change? I can imagine it being an intentional fix for some issue that Apple customers ran into, but I can also imagine this could be unintentional or a bug, so I wanted to double check. Thank you
1
1
346
Aug ’24
Delay in APNS notification delivery
One of our customer has reported that pushes are delivered with big delay. Pushes are send to APNS in less than 5 seconds as per our statistics but it takes sometimes up to 5 minutes for notifications to arrive on devices. The authentication used is certificate based even though token based authentications is also tried out before. They have around 346252 subscribed device tokens (users) to which important pushes are send out. We use HTTP/2 based connections and reuses the connections. To avoid push bursts over selective connection, we distribute push traffic across different APNs servers. Sample headers: [:method: POST, :authority: api.push.apple.com, :path: /3/device/, :scheme: https, apns-expiration: 1723721057, apns-priority: 10, apns-topic: , authorization: bearer ] Sample payload: {"reference":"{"id":"lux.DvKH5JCtCcus5EaW5Houcn","type":"articleReference"}","aps":{"badge":0,"alert":{"body":"„Warum werden nicht ein paar gesetzliche Feiertage gestrichen?“ Munich-Re-Chef Joachim Wenning fordert, dass die Deutschen mehr arbeiten sollten"},"sound":"default","mutable-content":1},"tracking":"{"piano":{"ivw_category":"thema_wirtschaft","pcat":"paid","date_sent":1723629099370,"main_topic":"unternehmen","push_channel":"11124","section":"wirtschaft","object_id":"lux.DvKH5JCtCcus5EaW5Houcn","push_text":"warum_werden_nicht_ein_paar_gesetzliche_feiertage_gestrichen_munich_re_chef_joachim_wenning_fordert_dass_die_deutschen_mehr_arbeiten_sollten_plus"},"ivw":{"ivw_category":"thema_wirtschaft","ivw_code":"spracheDE/formatTXT/erzeugerRED/homepageNO/auslieferungMOB/appYES/paidNO/inhaltTHEMA/merkmalWIRTSCHAFT/ressortWIRTSCHAFT/portalAPP"},"firebase":{"ivw_category":"thema_wirtschaft","pcat":"paid","date_sent":1723629099370,"main_topic":"unternehmen","push_channel":"11124","section":"wirtschaft","object_id":"lux.DvKH5JCtCcus5EaW5Houcn","push_text":"warum_werden_nicht_ein_paar_gesetzliche_feiertage_gestrichen_munich_re_chef_joachim_wenning_fordert_dass_die_deutschen_mehr_arbeiten_sollten"}}"} Please let us know what could be the reason and steps we could take to avoid such delivery delays.
3
0
329
Aug ’24