Notification Center

RSS for tag

Create and manage app extensions that implement Today widgets using Notification Center.

Notification Center Documentation

Posts under Notification Center tag

71 Posts
Sort by:
Post not yet marked as solved
0 Replies
320 Views
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?
Posted
by
Post not yet marked as solved
1 Replies
450 Views
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.
Posted
by
Post not yet marked as solved
0 Replies
293 Views
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.
Posted
by
Post not yet marked as solved
0 Replies
297 Views
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
Posted
by
Post not yet marked as solved
0 Replies
503 Views
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?
Posted
by
Post not yet marked as solved
1 Replies
515 Views
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!
Posted
by
Post not yet marked as solved
0 Replies
614 Views
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)") } }
Posted
by
Post not yet marked as solved
0 Replies
335 Views
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)
Posted
by
Post not yet marked as solved
0 Replies
349 Views
Hi, A few days ago, I tested actionable notifications, and I get the buttons configured for the category displayed on my iPhone when I get an alert notification. The buttons used to be displayed on the apple watch as well, but now I only get "Dismiss". Any reason for that?
Post not yet marked as solved
1 Replies
483 Views
Using iOS 17 and React Native, I managed to call a RN function from iOS Live Activities button widget using LiveActivityIntent and NotificationCenter. However, in addition to calling a function into RN, I also would like to open the same React Native app (put it in foreground) (mimic the default Live Activity tap behavior). Can someone please tell me how to do it? If I click the button, it executes the function only, but does not open the app... @available(iOS 17.0, macOS 13.0, watchOS 9.0, tvOS 16.0, *) struct SuperCharge: LiveActivityIntent { static var title: LocalizedStringResource = "Emoji Ranger SuperCharger" static var description = IntentDescription("All heroes get instant 100% health.") func perform() async throws -> some IntentResult { print("calling function from Swift!!!!!") NotificationCenter.default.post( name: Notification.Name("InvokeEvent"), object: nil, userInfo: ["message": "Hello from Widget"] ) return .result() } } I reviewed the apple docs below, but could not find an answer or example: https://developer.apple.com/documentation/widgetkit/linking-to-specific-app-scenes-from-your-widget-or-live-activity
Posted
by
Post not yet marked as solved
3 Replies
695 Views
Hello all. I face problem with Notification Service Extension. User mobile receive notification without any problem, payload contain mutable-content:1 inside it ( also, full example of payload is attached ), but, NSE didn't run correctly, also, original content of notification didn't saw ( in case, and there is a crash because of something wrong in app ) I checked device logs, and I see next errors: [*] Mutated notification request is nil, will supress original content; notificationRequest=7019-8D60, error=Error Domain=NSCocoaErrorDomain Code=4097 "connection from pid 487 on anonymousListener or serviceListener" UserInfo={NSDebugDescription=connection from pid 487 on anonymousListener or serviceListener}, runtime: 0.410339 [*.notificationextension] Service extension connection encountered an error: sessionUUID=88D39801-67DF-4DC7-AA70-2AD7E8634369, error=Error Domain=NSCocoaErrorDomain Code=4099 "The connection from pid 505 on anonymousListener or serviceListener was invalidated: client is gone." UserInfo={NSDebugDescription=The connection from pid 505 on anonymousListener or serviceListener was invalidated: client is gone.} example of payload: "aps": { alert = { "loc-args" = ( msisdn ); "loc-key" = "key"; }; badge = 1; "content-available" = 1; "mutable-content" = 1; sound = "pnsound.aiff"; }, "m": CFG, "j": msisdn, "t": id, "n": M] This problem is face from time to time, I can't catch this problem on same build and same environment, also, this problem can occur for some time, and after that everything will be fine
Posted
by
Post not yet marked as solved
0 Replies
560 Views
As iOS 17 has begun to roll out, our team has noticed a crash increasing in our production application. This crash revolves around UNUserNotificationCenter and calling .getNotificationSettings(completionHandler:) in order to retrieve the users UNNotificationSettings. Upon adding extra logging to our production app, we've determined that in the callback of getNotificationSettings, trying to access the returned value UNNotificationSettings is what's crashing our app. Here's our stacktrace: Crashed: com.apple.usernotifications.UNUserNotificationServiceConnection.call-out EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000000000000000 0 libswiftCore.dylib 0x3fd3ec swift_getObjectType + 40 1 libswiftCore.dylib 0xd660c _print_unlocked<A, B>(_:_:) + 348 2 OurApp 0x23f8ec closure #1 in closure #1 in MessagingPermissionsModel.authorizationStatus.getter + 155 (MessagingPermissionsModel.swift:155) 3 OurApp 0x8bd98 partial apply for closure #1 in UNUserNotificationCenter.getNotificationSettings(completionHandler:) + 28 4 OurApp 0x8b9bc thunk for @escaping @callee_guaranteed (@guaranteed UNNotificationSettings) -> () + 52 (<compiler-generated>:52) 5 libdispatch.dylib 0x26a8 _dispatch_call_block_and_release + 32 6 libdispatch.dylib 0x4300 _dispatch_client_callout + 20 7 libdispatch.dylib 0xb894 _dispatch_lane_serial_drain + 748 8 libdispatch.dylib 0xc3f8 _dispatch_lane_invoke + 432 9 libdispatch.dylib 0x17004 _dispatch_root_queue_drain_deferred_wlh + 288 10 libdispatch.dylib 0x16878 _dispatch_workloop_worker_thread + 404 Here is also the variable in which this crash is happening (along with our extra logging). We wrap the auth status in a RxSwift single for subscribers. 149 private var authorizationStatus: Single<UNAuthorizationStatus> { 150 Logger.debug("MessagingPermissionsModel.authorizationStatus GET") 151 return Single.create { [weak self] observer -> Disposable in 152 Logger.debug("MessagingPermissionsModel.authorizationStatus Single created") 153 self?.userNotificationCenter.getNotifictionSettings { [weak self] settings in 154 Logger.debug("MessagingPermissionsModel.authorizationStatus Retrieved notification settings") 155 (Crashes here) Logger.debug("MessagingPermissionsModel.authorizationStatus Settings \(settings)") 156 Logger.debug("MessagingPermissionsModel.authorizationStatus Auth Status \(settings.authorizationStatus)") 157 Logger.debug("MessagingPermissionsModel.authorizationStatus Observer \(String(describing: observer))") 158 Logger.debug("MessagingPermissionsModel.authorizationStatus Self \(String(describing: self))") 159 observer(.success(settings.authorizationStatus)) 160 Logger.debug("MessagingPermissionsModel.authorizationStatus Observer invoked") 161 } 162 Logger.debug("MessagingPermissionsModel.authorizationStatus Disposable will return") 163 return Disposables.create() 164 } 165 } From what we've seen so far, I'm lead to believe this is a bug in iOS 17.
Posted
by
Post not yet marked as solved
0 Replies
380 Views
i does not implementation background push notification in my app. however i found my app launch in background(applicationState is equal to background inapplicationDidFinishLaunch method) and launchOptions contained UIApplicationLaunchOptionsRemoteNotificationKey. the value of UIApplicationLaunchOptionsRemoteNotificationKey does not contained content-available : 1 is it a bug or sepcial case ?
Posted
by
Post not yet marked as solved
2 Replies
482 Views
I want to change the notification tap behaviour. As we know that default behaviour of notification is when we tap or touch on notification then it opens the app and when we press and hold (long press) the notification then its shows the notification preview (should become interactive notification) and we can interact through notification without opening the app. 
But I want to reverse the default behaviour of notification i.e. when we tap or touch on the notification then it should open the notification preview (should become interactive notification) and we can interact through notification without opening the and when we press and hold the notification then it should open the app.

Could you please guild me how can I implement this notification feature.
Posted
by
Post not yet marked as solved
0 Replies
352 Views
I use a UNNotificationServiceExtension to download an image into temporaryDirectory that is attached as an UNNotificationAttachment to the notification. FileManager.default.temporaryDirectory .appendingPathComponent(UUID(). .appendingPathExtension(image.ext) data.write(to: fileUrl) let attachment = ... attachments.append(attachment) The documentation for UNNotificationAttachment say I am responsible to manage the storage space for such attachments: The system limits the amount of storage space allocated for attachments for each app. To delete attachments, use the methods of the UNUserNotificationCenter class to remove the notification requests that contain those attachments. https://developer.apple.com/documentation/usernotifications/unnotificationattachment Do I need to check in my AppDelegate if there are any notifications that are no longer displayed and remove their files? If so, how how to get a list of notifications that are no longer displayed?
Posted
by
Post not yet marked as solved
0 Replies
356 Views
Hi, I was wondering if it was possible to get a notification when there is a change to the forced defaults that my app uses. This forced defaults are sent via MDM using the com.apple.ManagedClient.preferences payload type. I've seen that UserDefaults.didChangeNotification is available but it only works if the change is made from inside the app and not if the payload gets updated by the MDM. class MySettings { private let defaults = UserDefaults(suiteName: "com.myapp.app.mysettings") init() { // Somehow register for notifications } func defaultsChanged() { // This would be called when the defaults change } }
Posted
by
Post not yet marked as solved
1 Replies
609 Views
UPDATE: So I discovered that if UIScreen.main.traitCollection.userInterfaceStyle is called in a notification service extension then it doesn't detect any change to the iPhones light/dark mode unless the phone is restarted. (I tried with other extensions, changes are detected immediately in other extensions, however not with a notification service extension nor in a notification content extension). ORIGINAL POSTING: I've got a notification service extension which is populating the notification with images before it's displayed. The images are part of an image set with different images for light and dark modes. What I've discovered is that which image is displayed in the notification depends upon whatever mode the phone was in when the app was installed or when the phone was restarted and it will stay like that for any subsequent posted notifications forever regardless of what the phone's light/dark mode setting is, unless the phone is restarted. Here's an example to illustrate what I mean, here's an image set in the Media.xcassets for the extension, its called "Grunt". And here's some code in the extension: notificationContent!.title = "GRUNT" if let url = URL(forImageResource: "Grunt") { do { let attachment = try UNNotificationAttachment(identifier: "imageAttachment", url: url) notificationContent!.attachments = [attachment] } catch { NSLog("error") } } contentHandler(notificationContent!) When the app is installed, if the phone is set to light mode, then when a notification is posted the 2x Light image is displayed in the notification. If the phone's setting is then changed to dark, then the 2x Light image still continues to displayed in all subsequent notifications that get posted. Conversely, if the phone is set to dark mode when the app is installed then the 2x Dark image is displayed in a notification, similarly if the phone's settings are changed to Light, the Dark image continues to be displayed for any new notifications posted. Until the phone is restarted - then any new notification display in accordance with whatever the phone's dark mode is set to at the time the phone is restarted. In other words, if the phone's light/dark mode setting is changed, new notifications posted don't display the appropriate light/dark image from the image set unless the phone is restarted. (Occurs with both iOS 16 and 17)
Posted
by
Post not yet marked as solved
0 Replies
385 Views
I've found an issue introduced in iOS 17. Apps that have notifications in CarPlay (Message, Whasta, Telegram, etc...) can play sounds without the need of displaying any notification alert. If you turn "Show in CarPlay" to off, which is the default value for all other apps, sound will not play unless you check at least one alert type.
Posted
by