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

Critical Alerts and Notification Permissions
Back story: I'm developing an app that communicates with a personal medical device. We use critical alerts when we have hardware issues that could result in harm to the patient. The audio file is a 30 second file to make sure the patient is aware. If the app is open when they occur, we pop up a modal message in the app. When the user dismisses the notice, we call UNNotificationCenter::removeDeliveredNotifications(withIdentifiers:) to remove the critical alert and also to stop the audio file that is playing. This normally works fine. However we discovered that if the patient leaves critical alert enabled but disables notifications for our app, that we can still post the critical alert and it goes off. However when the user dismisses the message, the removeDeliveredNotifications call does not work. I did some debugging and if call getDeliveredNotifications with this permission combination, it return 0 (normally it would return 1). Does anyone know of another way to remove the critical alert in this situation? (or should I be submitting this as a bug?)
1
0
219
Sep ’24
Where to retrieve Live activity update token that was started with ActivityKit push notifications using push-to-start token?
I can successfully start a Live Activity using push-to-start token, but in order to update the Live Activity i need another token as stated in the docs: While the system starts the new Live Activity and wakes up your app, you receive the push token you use for updates. When the app is open, i can retrieve this update token and successfully update the Live Activity using this example code: func observeActivityPushToken() { Task { for await activityData in Activity<LiveActivityAttributes>.activityUpdates { Task { for await tokenData in activityData.pushTokenUpdates { let token = tokenData.map { String(format: "%02x", $0) }.joined() print("Push token: \(token)") } } } } } But when the app is closed, how/where do i manage to get this update token and send it to the server "when the system wakes up the app"?
2
1
295
Sep ’24
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
317
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
387
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
241
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
289
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
345
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
250
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
360
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) }
9
3
1.4k
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
317
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.2k
Aug ’24