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

72 Posts
Sort by:
Post not yet marked as solved
0 Replies
303 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 jithinb1.
Last updated
.
Post not yet marked as solved
1 Replies
411 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 Jonatus.
Last updated
.
Post not yet marked as solved
0 Replies
378 Views
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.
Posted Last updated
.
Post not yet marked as solved
0 Replies
269 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 Last updated
.
Post not yet marked as solved
0 Replies
285 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 gralod.
Last updated
.
Post not yet marked as solved
0 Replies
485 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 IosDevAZ.
Last updated
.
Post not yet marked as solved
1 Replies
488 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 YR23.
Last updated
.
Post not yet marked as solved
1 Replies
494 Views
I am working on an interactive widget and merging changes provided by a user over it with the app. I store my data, using Core Data. However, I noticed an issue with sync between other user's devices after that person made a change over the widget (in my case, it is completing a task). Here is my schema: Main app: it looks for relevant transactions (https://developer.apple.com/documentation/coredata/consuming_relevant_store_changes). When it found that one, the app merges changes: if transaction.author == "widget" { if let userInfo = transaction.objectIDNotification().userInfo { NSManagedObjectContext.mergeChanges(fromRemoteContextSave: userInfo, into: [taskContext]) } } Widget: If the user clicks on the checkbox in order to complete a task, using an AppIntent class, app creates an identical NSPersistentCloudKitContainer and completes the task. However, in that case, the NSPersistentCloudKitContainer of the widget does not look for changes. That works correctly. However, only in a local environment. Here's why: If I complete a task (using a widget) and launch the app on the same device, the change will be synced correctly. If I complete a task (using a widget) (on device A) and launch the app on another device (on device B), the change will not be applied (on device B), until I open the app on the device that I made the change on (on device A). If I open the app on device B after I opened it on device A (and the changed has been applied), on device A I get a remote notification with the author value = 'NSCloudKitMirroringDelegate.import', not 'widget'. The point of my issue is that the remote notifications about changes made, using widgets, does not arrive to other devices like notifications initialised by the main app. Thank you in advance!
Posted Last updated
.
Post not yet marked as solved
0 Replies
588 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 j_ptron.
Last updated
.
Post not yet marked as solved
1 Replies
555 Views
Hi everyone, I have two questions regarding some issues with the new iOS 17 interactive widgets and live activities. Question 1: How can I update other Widgets and/or Live Activities, based on an AppIntent interaction in either one? I have several widgets that is displaying the same information, but in different sizes (Small, Medium, Large and Lockscreen). Most of our users are using many of them together on their Lockscreen and Home Screen. When they are interacting with the AppIntent button in either the Widget og LiveActivity it does not update and vice-versa. Based on the documentation it's pretty clear that interacting with a Widget it will update the timeline for that specific widget after the .perform() in the AppIntent is returned. Unfortunately, I also need to update the LiveActivity and the other TimeLines for the rest of the widgets. I have tried to use the WidgetCenter.shared.reloadAllTimelines() but it seems like it does not update the LiveActivity or the LockScreen widgets correctly. Question 2: How can I update and reschedule the local notifications based on the interaction in the Widget and Live Activity? The app sends a local notification whenever an activity starts or stops (e.g like a pomodoro timer with intervals). Let's assume the user have setup a 30 minute activity in the app, but now decides to pause the activity from either the widget or live activity. I then want to remove the scheduled local notification that was supposed to be fired in 30 minutes. I haven't been able to read from the documentation if this is possible, but would like to know if there is any way this can be performed. Looking forward to hear if anyone have encountered the same challenges :)
Posted
by JMCPH.
Last updated
.
Post not yet marked as solved
1 Replies
592 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 mungbeans.
Last updated
.
Post not yet marked as solved
0 Replies
324 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 Last updated
.
Post marked as solved
3 Replies
4.3k Views
Using addObserver func of NotificationCenter.default, subscribing to UIApplication.willEnterForegroundNotification does not work when the backgrounding is triggered from Notification Center (swipe down from top when app is active to get Notification Center).  It also seems that UIApplication.willResignActiveNotification is called twice, based on Print() logs, when Notification Center triggers the backgrounding. If you background the app via lock screen or manual swipe, or switch to another app, the UIApplication.willEnterForegroundNotification does get called, so it seems to be specific to Notification Center. UIApplication.willResignActiveNotification does fire correctly but then resuming the app never calls the appMovedToForeground func below: notificationCenter.addObserver(self, selector: #selector(appMovedToForeground), name: UIApplication.willEnterForegroundNotification,object: nil) occurs on: iOS 14.4.2, iPhone 11 & iOS 14.6, SE(2)
Posted Last updated
.
Post not yet marked as solved
0 Replies
333 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?
Posted Last updated
.
Post not yet marked as solved
1 Replies
448 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 romansf20.
Last updated
.
Post not yet marked as solved
3 Replies
657 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 elaits.
Last updated
.
Post not yet marked as solved
2 Replies
466 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 iOS141025.
Last updated
.
Post not yet marked as solved
0 Replies
535 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 Last updated
.
Post not yet marked as solved
0 Replies
361 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 Sodasi.
Last updated
.