As per subject. Is this possible at all?
The WWDC video only talks about the communication / push notifications. There doesn't seem to be any update to UNNotificationContent to allow setting of attributed strings.
If your app makes use of communication notifications you can even include Genmoji and other image glyphs in your notifications with the new "UNNotificationAttributed MessageContext API". For push notifications, the payload just needs to contain a rich text representation that may contain image glyphs.
We recommend that you use a Notification Service Extension to parse the rich text, download assets, create the attributed body and update the notification content
User Notifications
RSS for tagPush user-facing notifications to the user's device from a server or generate them locally from your app using User Notifications.
Posts under User Notifications tag
159 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
For a few years now, I have submitted requests for com.apple.developer.usernotifications.filtering entitlement, but never got an approval/denial response from apple. even after contacting them via email, still didn't get a response about the request status.
our app is an emergency alerts app, this entitlement is crucial for our app reliability.
Last request i have sent has Case-ID: 7377207
I have a Push Notification Service Extension, which is processing notification payload to attach image, if imageUrl is key is present.
I use this simple code to perform the download:
let downloadTask = URLSession.shared.downloadTask(with: urlRequest) {
[weak self] tempURL, response, error in
/// parse results...
}
Notification payload contains "mutable-content" : 1 inside aps. It's entirely randomly will it work or not.
When it doesn't work, I get this error:
Error Domain=NSPOSIXErrorDomain Code=1 "Operation not permitted" UserInfo={NSErrorFailingURLStringKey=https://w7.pngwing.com/pngs/1005/607/png-transparent-african-elephant-animal-elephant-thumbnail.png, NSErrorFailingURLKey=https://w7.pngwing.com/pngs/1005/607/png-transparent-african-elephant-animal-elephant-thumbnail.png, _NSURLErrorRelatedURLSessionTaskErrorKey=(
"LocalDownloadTask <4A847242-2314-4125-99E4-A424CF4B4B7C>.<7>"
), _NSURLErrorFailingURLSessionTaskErrorKey=LocalDownloadTask <4A847242-2314-4125-99E4-A424CF4B4B7C>.<7>}
I have no idea what Apple's internal code throws this error, what could possibly go wrong here.
This is happening for a while now, I just re-tested on iOS 17.5.1 on 14 Pro. App is compiled using Xcode 15.4 and Swift 5.10, latest SDK.
Not sure is it relevant but main iOS app has DataProtection capability set to Complete.
Hi Everyone,
I am setting apns expiration in the push payload sending to apple server. push expires in 30 seconds as per the configuration using development certificates.
However the same logic does not work when I use adhoc profile but works in App store .
Any specific reason it does not work using adhoc profile?
I have implemented a NEPacketTunnelProvider in my app, which sends local notifications to the user when the server is down. While the notifications are displayed successfully, I encountered an issue when changing the system locale settings on iOS. Specifically, the notifications still display in the previous locale, even after the system locale has been changed. The locale of the notifications only updates if I restart the device.
I am currently using Locale.current for setting the locale in my notifications. I have also tried using Locale.preferredLanguages, but it seems that the locale does not properly update in real-time.
We recently noticed that our app is receiving duplicate notifications, and this is impacting multiple users, and we verified from our server that we are sending the notifications only once
This is a sample payload of the notifications we are sending
{
"aps": {
"alert": {
"title": "title",
"body": "body"
},
"category": "test",
"mutable-content": 1
},
"navigateTo": "test",
"imageUrl": "test"
}
Also a user with IOS 17.5.1 reported this issue also
I'm sending a push notification using Noticed Gem during the night when my phone is in airplane mode. When I wake up and disable the airplane mode, I don't get the push notification.
These are the settings:
` def ios_format(apn)
apn.custom_payload = { universal_link: url }
apn.alert = { title: title(recipient), body: message(recipient) }
apn.sound = 'default'
apn.priority = '10' # Send immediately, bypassing the
end
`
default expiration is supposed to be 30 days.
How can I debug/fix the problem? (with noticed gem)
I checked Apple consoleKIT, and I don't see discarded notifications.
Thanks
Hello There!,
I'm currently working on an App with an implemented timer. It was initially planned, that the User will get a notification when the timer ends. Everything works fine until the timer ends and the phone doesn't gets any notification...
This is my code:
import SwiftUI
import Combine
import UserNotifications
struct TimerView: View {
@State private var timeRemaining: TimeInterval
@State private var timerActive = false
@Binding var studyTime: Int
@Binding var selectedExam: Exam
init(studyTime: Binding<Int>, selectedExam: Binding<Exam>) {
_studyTime = studyTime
_selectedExam = selectedExam
_timeRemaining = State(initialValue: TimeInterval(studyTime.wrappedValue * 60))
}
var body: some View {
VStack {
ZStack {
Circle()
.trim(from: 0, to: CGFloat(timeRemaining / (TimeInterval(studyTime * 60))))
.stroke(Color.purple, lineWidth: 15)
.rotationEffect(.degrees(-90))
.animation(.linear(duration: 1))
.padding(40)
Text("\(timeRemaining.formattedTime)")
.font(.system(size: 50))
}
Button(action: {
self.timerActive.toggle()
}) {
Text(timerActive ? "Stop" : "Start")
.font(.title)
.padding()
}
.foregroundColor(.white)
.background(timerActive ? Color.red : Color.green)
.cornerRadius(10)
.padding()
}
.onReceive(timer) { _ in
guard self.timerActive else { return }
if self.timeRemaining > 0 {
self.timeRemaining -= 1
} else {
self.timerActive = false
sendNotification()
}
print("Time Remaining: \(self.timeRemaining)")
}
.navigationTitle($selectedExam.wrappedValue.subject)
.navigationBarBackButtonHidden(true)
.onDisappear {
// Actions if the timer View disappears
}
}
var timer: AnyPublisher<Date, Never> {
Timer.TimerPublisher(interval: 1.0, runLoop: .main, mode: .default)
.autoconnect()
.eraseToAnyPublisher()
}
func sendNotification() {
let content = UNMutableNotificationContent()
content.title = "Lernzeit vorbei"
content.body = "Deine Lernzeit für \(selectedExam.subject) ist abgelaufen!"
content.sound = UNNotificationSound.default
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 1, repeats: false)
let request = UNNotificationRequest(identifier: "timerNotification", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request) { error in
if let error = error {
print("Fehler beim Hinzufügen der Benachrichtigung zur Warteschlange: \(error.localizedDescription)")
} else {
print("Benachrichtigung zur Warteschlange hinzugefügt")
}
}
}
}
extension TimeInterval {
var formattedTime: String {
let minutes = Int(self) / 60 % 60
let seconds = Int(self) % 60
return String(format: "%02i:%02i", minutes, seconds)
}
}
I looked it up and the app is allowed to send every type of notification... (this is initialized in another part of the code)
I am building an application where I need to implement a use case where a local notification is set for a specific date / time (e.g 05/6/24 8 PM) to display to the user (e.g. "Take your Meds") and I want him to continue to get that alert every X minutes (e.g. every 2 minutes) until I cancel it (e.g. when the user indicates he has taken his medicene).
NOTE: I do NOT want to rely on push notifications from the server for doing the reminders because it needs to work when the device is off the network (like on a plane or a cruise ship in the middle of the ocean or whatever).
This would seem to be a pretty common use case, but looking at the previous and existing local notification frameworks, I only see the option to create a calendar based trigger with a boolean repeat (UNCalendarNotificationTrigger) or a time interval based trigger with a boolean repeat (UnTimeIntervalNotificationTrigger), but nothing that combines these in a way that allows me to implement the above stated use case.
We are attempting to enable provisional notifications in our app, but some internal users on iOS 17 are reporting that they are not receiving the "Keep" and "Turn off" buttons that provisional notifications are supposed to have - in other words they just come in as regular quiet notifications.
I have confirmed that these users are doing a fresh install of our app, and at no point are they ever receiving a permission prompt to turn on notifications. Their UNAuthorizationStatus is correctly being set to provisional. Their notification settings are being set to the following, which seems correct:
I have not been able to reproduce this issue on any of my own devices, but these users can do so consistently. What could possibly cause this? Some misconfiguration on our end, our some hidden iOS setting somewhere?
Hi, I am trying to add in a push notification but the send push notifications function does not seem to be working. Can someone help?
func sendNotification() {
print("Bluetooth device disconnected. Sending notification.")
let content = UNMutableNotificationContent()
content.title = "Car Disconnected"
content.body = "Please key in where you have left your car"
content.sound = UNNotificationSound.default
// Create a trigger to send the notification immediately
let request = UNNotificationRequest(identifier: "BluetoothDisconnected", content: content, trigger: nil)
UNUserNotificationCenter.current().add(request) { error in
if let error = error {
print("Error adding notification request: \(error.localizedDescription)")
} else {
print("Notification request added successfully.")
}
}
}
I schedule a local notification to remind me to check in at work at 8 am if I am not already checked in, the code is working fine when app is in foreground, but when I kill the app, it alway show alert no matter if I already checked in or not.
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let isCheckedIn = AppManager.shared.isCheckedIn()
if isCheckedIn {
completionHandler([])
} else {
completionHandler([.list, .sound, .banner])
}
}
Steps to reproduce:
Install & Launch App
When push notifications are registered, the push notification token received is a "production" push notification token rather than a "development" push notification token.
We are trying to test on the sandbox environment with development push notification tokens, however the apn-environment for all builds we release via TestFlight are being set to "production". We wish to distribute builds via TestFlight with apn-environment set to "development".
At the moment we have only found one way to run the app with apn-environment set to "development" which is to "Export" a Debug build, then manually install it on a device via iTunes on Windows machines. This method is not efficient or considered seamless enough for non-technical testers and stakeholders. They require a seamless way to receive Debug builds via TestFlight without resorting to other third-party platforms which allow us to manually upload the "Exported Debug build".
If anyone knows how to upload a "Debug" build to Testflight which will allow the user to receive a sandbox development push token with "apn-environment" set to development I would really appreciate it.
Hi,
I'm triggering a notification from the audio interruption handler (but also have a debug button set to trigger it manually) and it frequently does not show up. I don't think I have ever seen it show up when the watch face is off.
I have created a singleton class to trigger this notification as follows. Note that I use a UUID in the identifier because an old thread here suggests this is necessary, but it makes no difference as far as I can tell.
Any ideas? I'd like this notification to be reliable. I'm also surprised that with trigger set to nil, it does not trigger instantaneously.
Any help would be much appreciated!
Thanks,
-- B.
import Foundation
import UserNotifications
class NotificationSender: NSObject, UNUserNotificationCenterDelegate {
static let shared = NotificationSender()
override init() {
super.init()
let center = UNUserNotificationCenter.current()
center.requestAuthorization(options: [.sound, .badge]) { granted, error in
if granted {
print("Notification permission granted")
} else {
print("Notification permission denied")
}
}
center.delegate = self
// Define the action to open the app
let openAction = UNNotificationAction(identifier: "openAction", title: "Open App", options: [.foreground])
// Add the action to the notification content
let category = UNNotificationCategory(identifier: "resumeAudioCategory", actions: [openAction], intentIdentifiers: [], options: [])
center.setNotificationCategories([category])
}
func sendNotification() {
let center = UNUserNotificationCenter.current()
let content = UNMutableNotificationContent()
content.title = "Recording Interrupted"
content.body = "You will need to restart it manually."
content.categoryIdentifier = "resumeAudioCategory"
// Create the notification request
//let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 5, repeats: false)
let request = UNNotificationRequest(identifier: "ResumeAudioNotification-\(UUID().uuidString)", content: content, trigger: nil)
center.add(request) { error in
if let error = error {
print("Error adding notification request: \(error)")
}
}
}
// Handle notification when the app is in the foreground
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
// Display the notification while the app is in the foreground
completionHandler([.sound, .badge, .banner, .list])
}
// Handle notification response
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {
// Handle the user's response to the notification
// For example, navigate to a specific screen in your app
completionHandler()
}
}
Hello, I developed an application that uses iBeacons to create events, however when the app is in the terminated state I notice that part of my code is activated but the rest of the process is not activated ex : ranging beacon and notification. Is there a way to completely wake up my app when it is in terminated state or at least send a notification to the user to inform them that the app must be opened to put it back in background state so that the app working correctly?
Hello everyone,
I have been working on a macOS app that utilizes push notifications for the past year. Up until recently, everything was functioning correctly. However, now I'm experiencing issues where push notifications are either not being delivered at all or are experiencing significant delays, sometimes up to 10 minutes. Setting the priority header to 10 hasn't made any difference. I am currently using development push notifications, but the issue persists when switching to the production environment.
I'm curious if anyone else has encountered similar problems. When checking the push console, it frequently reports that the device is offline, even though it's actually online ("discarded as device was offline"). Occasionally, notifications are delivered promptly, but this is becoming increasingly infrequent.
This issue has been consistently reported by our testers, particularly after they updated to macOS Sonoma. Any insights or assistance you can provide would be greatly appreciated.
Hello fellow developers, I am creating an application and it contains critical alerts and for that I have given the permissions but unable to find any implementations. I am using Flutter environment to develop my application and want that the application should emit a sound even if it is silent or in 'Do Not Disturb' mode.
Hello Apple Developer Community,
I am reaching out for insights regarding an issue we're facing with Apple Push Notification Service (APNS). Despite successful implementation and functioning for other apps, we are consistently receiving a 400 TopicDisallowed error when trying to send push notifications to one specific app. Here's a detailed overview:
Issue Summary: Push notifications sent from our server to a specific app result in a 400 TopicDisallowed error from APNS. This problem is unique to this app; notifications to other apps with similar configurations are successful.
Successful Tests via Apple CloudKit Console: Notably, when using the Apple CloudKit Push Notification Console, push notifications to the problematic app are sent successfully, indicating the app's basic setup is configured correctly.
Key Details:
The topic field in the push notification request matches the app's bundle ID exactly.
The app is downloaded from the App Store, and we are using the production environment on our server.
Payload structure, APNS endpoint, and APNS Auth Key are consistent across all apps we manage.
Device tokens for the problematic app validate successfully using the tool in the push notification console.
Detailed server-side logging has not revealed significant differences between successful and unsuccessful push notification requests.
Given these factors, we are struggling to identify the root cause of this specific issue. I am wondering if anyone in the community has faced a similar problem or could offer any insights.
Any help or guidance would be immensely appreciated.
Thank you in advance!
I noticed that the numbers given for the individual states do not add up; i.e. if I add everything other than "Received by APNs" I get what amounts to ~95% of that. Is that expected? And if so what happened to the remaining 5%?
I made a simple applescript app to run a shell script and display a notification when it ends, it runs pretty well but I did't want the app appearing in the dock, so I added LSUIElement = true in the info.plist, and now the script runs but the app does not notify. Is there a way to have a background app (does not appear in the dock) with the ability to display notifications?