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?)
Notifications
RSS for tagLearn about the technical aspects of notification delivery on device, including notification types, priorities, and notification center management.
Post
Replies
Boosts
Views
Activity
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"?
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.
I am using a standard PHP script to send a push notification using a JSON web token (JWT). This works perfectly from the MacOS command line.
But the same setup will not go through to the sandbox from a website on cPanel using PHP 8.3.
The error is: Curl failed: Private key does not match the certificate public key
There are no errors in the error logs.
Any ideas?
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.
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.
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.
I need to implement function of use offer code in app store. I used offer code in app store and the exchange has been successful, but apple store server not send the v2 notification to my server, What should I do?
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?
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 ?
Hello, I'm using 'App Store Server Notifications V2'.
I have a question about 'CONSUMPTION_REQUEST' notification in 'notificationType'.
What problems can occur if the send consumption information API is called without user consent? For example, could there be penalties such as refusing to update the app or blocking the service?
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?
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)
}
Currently if the app is hidden and locked behind face id even though the notifications are not displayed but the Notification Service Extension still wakes up for the notification.
Is it the expected behaviour ? Or should we expect the NSE would not be used as well when the app is hidden.
Gittim macbook pro aldım ve xcode yükledim.
key>CADisableMinimumFrameDurationOnPhone ve bu kodu iphone 13 pro telefonuma nasıl yüklerim
Is there a way to export all push notification console information via API or webhook?
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 ?
I have triggered few notifications, and they were delivered to my iPhone with a delay of several hours. Could you please assist us in resolving this issue?
Device: iPhone 15
OS Version: 17.5.1
After uploading the PushCertificateRequest.plist file in the "Create a New Push Certificate" form on the Apple Push Certificates Portal, I receive a "The page you’re looking for can’t be found." response.
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 .