Hi All
I have some customer sound file named as .x-wav / .x-m4a, when specify sound file with extension .x-wav, like
content.sound = [UNNotificationSound criticalSoundNamed:@"mysound.x-wav" withAudioVolume: 1.0];
it will play defaultcrititicalsound.
if I tried
content.sound = [UNNotificationSound criticalSoundNamed:@"mysound.wav" withAudioVolume: 1.0];
then it worked
Notification Center
RSS for tagCreate and manage app extensions that implement Today widgets using Notification Center.
Posts under Notification Center tag
74 Posts
Sort by:
Post
Replies
Boosts
Views
Activity
Hi. I would like my App to be notified when the phone rings. No, not CallKit-CallKit is for VoIP and does not cover Cellular connections (as of 2/26/24) but, thanks. To continue..
I understand ages-ago there was a Telephony Kit or Framework but, has been discontinued. Has it been replaced with something else?
I would like something that seems very simple:a) when the phone rings my App is notified, b) when it stops ringing (combine all possibilities; sent to voicemail, user cancels, user answers) my App is notified.
Yes, I understand UserNotifications can make things run but, as I understand it this feature is for the App to schedule notifications, not receive them? If you know of something in UserNotifications that I can leverage I would appreciate your input.
Lacking other possibilities I find myself wondering about Siri integration. Siri is notified about system events and generates notifications based upon these events. Is there some way to place my App downstream from Siri and receive system notifications? Thanks everyone.
I would like the notification to stay.
I have inter alia following code, it works well but the notification disappears after 5 seconds (both when app is running or terminated):
@UIApplicationDelegateAdaptor(AppDelegate.self) var appDelegate
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate {
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions:
[UIApplication.LaunchOptionsKey : Any]? = nil) -> Bool {
let nc = UNUserNotificationCenter.current()
nc.delegate = self
return true
}
public func userNotificationCenter(_ center: UNUserNotificationCenter,
willPresent notification: UNNotification,
withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
let request = notification.request
let identifier = request.identifier
let userInfo = notification.request.content.userInfo
completionHandler([.banner, .list, .badge, .sound])
}
Hi,
I just downloaded Xcode 15.3 beta 3 and went to create a new project, however I cannot find the widget extension. Do I have to enable this extension or download it?
When enabling direct C++ interoperability in Xcode, this simple code below
NotificationCenter.default.addObserver(self,
selector: #selector(subjectAreaDidChange(_:)),
name: .AVCaptureDeviceSubjectAreaDidChange,
object: nil)
gives me the following error
Type 'NSNotification.Name?' has no member 'AVCaptureDeviceSubjectAreaDidChange'
But if I switch C++ and Objective-C interoperability to just C / Objective-C then the code compiles without errors.
The issue seems to affect NSNotification.Name constants only from AVFoundation framework (although there maybe more).
Why do I get this error and how do I fix it?
We have noticed that the notification service extension stops working after app update for some users and it only starts working again after rebooting the device.
Does anybody else have similar problem and what was the solution?
An app is hanging randomly on app launch, after looking into it, it appears it's hanging on a call to UNUserNotificationCenter.current() calls. I say this because there's logging and the sometimes the last line logged is prior to a call to UNUserNotificationCenter()
I have a hang log (.ips file) rom the iPhone and at the bottom it says this.
I presume blockingThreadInfo is talking about the thread being blocked, and it identifies the topBlockingProcess as user notifications.
"blockingThreadInfo" : {
"topBlockingProcess" : "usernotificationsd",
The following is the code, why would this code cause a hang?
The problem occurs when there's lots of notifications that have been posted i.e. something like 100.
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(appBecameActive)
name: UIApplicationDidBecomeActiveNotification
object:nil];
@objc func appBecameActive() {
method1()
method2()
}
@objc func method1() {
UNUserNotificationCenter.current().getDeliveredNotifications { notifications in
if SettingsManager.isProductionFinalBuild() == false {
// Log notification center contents
for notification in notifications {
let title = notification.request.content.title
let targetId = notification.request.content.targetContentIdentifier
let threadId = notification.request.content.threadIdentifier
let categoryIdentifer = notification.request.content.categoryIdentifier
let identifier = notification.request.identifier
let info = notification.request.content.userInfo
Logger.trace("Previously delivered notification: title: \(title) identifier: \(identifier) threadId: \(threadId) category: \(categoryIdentifer) target id: \(String(describing: targetId)) userInfo: \(info)")
}
let matchchingNotifications = notifications.filter({ $0.request.identifier == kMdnAccountNotFoundNotificationIdentifier })
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [kMdnAccountNotFoundNotificationIdentifier])
}
}
func method2() {
UNUserNotificationCenter.current().removePendingNotificationRequests(withIdentifiers: [Constants.kWhatsNewNotificationIdentifier])
UNUserNotificationCenter.current().removeDeliveredNotifications(withIdentifiers: [Constants.kWhatsNewNotificationIdentifier])
}
Refer to the document:
https://developer.apple.com/documentation/usernotifications/setting_up_a_remote_notification_server/handling_notification_responses_from_apns#3394529
Error code 410, 'Unregistered' means: The device token is inactive for the specified topic.
But since February 1st, 2024, we did not got 'Unregistered' response any more. Do you know why ?
Hello Friends,
Could you please help me, whats wrong.
We have requirement that, when I receive remote notifications on device, I need to save it in to db (without tapping or opening notification banner), regardless my app is in Foreground or in Background.
I receive remote notifications on device & simulator both.
And
UNUserNotificationCenter delegates are being called if app is in foreground, but didReceiveRemoteNotification is not calling when app is background, not killed.
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// Save to DB
completionHandler(.newData)
}
I am having Xcode 15.2 & I tried on iOS versions 16.x & 17.x both on Simulator and on real devices.
// Added this code in App delegate
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge]) { granted, error in
if granted {
// User granted permission
DispatchQueue.main.async {
UIApplication.shared.registerForRemoteNotifications()
}
} else {
// User denied permission
}
}
Hi,
Please take a response to me about my Notification Service Entitlement Request.
I have requested 5 times but i didn't get any repsonses.
The application cannot be released because authorization is not granted.
Please check my case and leave a response as soon as.
Thanks,
Hello all,
I'm trying to build a watch app for a research study built around heart rate. Currently I have built a IOS app with a companion watchOS app for a firebaseDatabase connection. There are two remaining goals of this project that include the following:
While the watch app is in the background or when it's closed, is it possible for the apple watch to send a notification to the user if per say the user's heart rate goes over a custom threshold of 70bpm?
If so, how should this be implemented, and can the app be consistently monitoring the heart rate to get accurate realtime notifications, or is does apple limit background updates to periodically?
For this study, we want to analyze if user's actually open the watchapp because of the notifications. Is it possible to record data / track user interactions from the notifications?
If so, what kind of data can be tracked and how can it be stored?
My application requires me to clear all the notifications from the notification centre after a certain time duration.
I have tried using a combination of removeAllDeliveredNotifications & removeAllPendingNotificationRequests and they work fine up until OS 17.
So then I tried using removeDeliveredNotificationsWithIdentifiers & removePendingNotificationRequestsWithIdentifiers to check if it works consistently for all OS, but they hasn't worked either.
Is there any other way to clear the notifications consistently for all OS?
I have read through many forums but haven't found a solution for myself. When sending a notification, my NotificationService is not being called. I added it exactly as described in the official Apple tutorial and tried adding it again following other tutorials. Nothing helped. I haven't made any changes to it; it is in the same form as it is automatically created. Here it is:
import UserNotifications
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var bestAttemptContent: UNMutableNotificationContent?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.contentHandler = contentHandler
bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
// Modify the notification content here...
bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"
contentHandler(bestAttemptContent)
}
}
override func serviceExtensionTimeWillExpire() {
// Called just before the extension will be terminated by the system.
// Use this as an opportunity to deliver your "best attempt" at modified content, otherwise the original push payload will be used.
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
contentHandler(bestAttemptContent)
}
}
}
It does not print anything or hit any breakpoints. The notification payload looks like this:
{
"Simulator Target Bundle": "my.bundle",
"aps": {
"alert": {
"title": "Its title",
"body": "Very nice text"
},
"sound": "default",
"category": "CustomSamplePush",
"mutable-content": 1
}
}
Things I've tried:
Ensured the minimum version matches that of the application.
Configured info.plist, including UNNotificationExtensionCategory.
Ensured "Copy Only When Installed" is unchecked.
The Content extension works. However, prints and breakpoints are also not working.
Can I have a play/pause button in a Live Activities notification for the user to play an audio file if he/she chooses to? Kind of like a Spotify-style/Apple-Music-style play/pause/skip/rewind functionality but in the long-lasting Live Activities notification. Thank you.
Is there any way we can add a global setting for sound notifications on MacOS, or an option to have the default for newly installed apps to have sound notifications off by default?
Currently, sound notifications for apps need to be turned off one by one, which can be time intensive if lots of apps are installed.
Hello!
We have issue with updating multiply widgets of one kind.
For my case we have widget with one setting (period), and it will be common case for user to use two widgets of one kind to see data for two periods. Also user need to sign in our app to see info on widget.
After installing app we add 2 or 3 widgets of one kind on home screen. Now widgets saying what we need to sign in. We tap on widget, signing in, app sends WidgetCenter.shared.reloadAllTimelines(). When we going to home screen.
One widget updated and showing data and another non-updated and saying what we need to sign in
I've noticed there are certain apps which seem to track that I'm using my iOS device, and then send me push notifications based on my usage.
For example, I may pick up my phone in the middle of the night, unlock it, check my email, and minutes later, this app will send me a push notification attempting to sell me something.
Is an actually app permitted to track my activity/usage on my iPhone, outside of my activity and usage within that app? If so, where can I learn more about this? Or is this app in violation of some rule in the ToU?
Is it possible to pick the user's current device tone/sound as the Push Notification sound for my app programmatically. So that s/he does not miss out any notification just because of unsustainable sound.
I have gone through the UNNotificationSound Class, it provides the option to opt either the default or the custom sound. But, my concern is to auto pick the sound which user is using on his/her mobile.
Thanks in advance!
I have an app that schedules a handful of local notifications with trigger dates 1 to 4 weeks in the future. Each notification has a single image attachment with a JPEG sourced from the app's main bundle.
In development builds via Xcode, or builds via TestFlight, the notifications do appear in the notification center and they do display an image. However, in App Store builds, the notifications appear, but they do not display an image.
I have ruled out the following:
Images may not be included in the bundle
Images may be too large or unsupported (they are ~50KB 480x480 JPEGs, and the docs say validation happens at scheduling time)
The iOS device may have no free disk space
I'm leaning towards either:
Differences in file protection in App Store builds (though the docs say the app process must have access to the image and images in the bundle are copied)
The notifications are scheduled too far in the future and if the image is copied from the bundle to temporary storage, it gets wiped before display
Does anyone have any insight?
Sample code to schedule the notification below:
let dateComponents = // Some date in the future
let content = UNMutableNotificationContent()
content.title = // Some title string
content.body = // Some body string
content.userInfo = // Some app-specific dict
if let path = Bundle.main.path(forResource: "my-image-file-name", ofType: "jpg") {
let url = URL(fileURLWithPath: path)
do {
let imageAttachment = try UNNotificationAttachment(identifier: "", url: url) // Note the empty string identifier - the docs say one will be provided.
content.attachments = [imageAttachment]
} catch {
print("Failed to add image to local notification")
}
}
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: false)
let request = UNNotificationRequest(
identifier: "my-notification-id-here", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request) { error in
if let error = error {
print("Failed to add notification request: \(error)")
}
}
I'm using the flutter_local_notificationspackage to display notifications in and outside the app (background mode). Everything is working as expected on Android (debug + release) and iOS debug mode but, strangely, local notifications are not displayed in background mode for iOS release.
I don't know why the iOS release mode behaves differently, any thoughts?
Thanks.
What I already checked:
use of the latest version of the flutter_local_notifications package (v16.1.0)
checking "Signing & Capabilities" for both debug and release mode (Background modes : fetch, remote notifications)