NotificationCenter

RSS for tag

Create and manage app extensions that implement Today widgets using NotificationCenter.

NotificationCenter Documentation

Posts under NotificationCenter tag

74 Posts
Sort by:
Post not yet marked as solved
0 Replies
207 Views
I have an app that uses local notifications and everything is working fine but I'm debating how to handle pending notifications after the user turned off and turned back on notifications for your app. In other words, let's say that a notification is created and it's meant to be triggered on a certain day but the user turns notifications off the day before the trigger date, then he/she deletes the notification from the app (UI) while notifications for your app were turned off and then after a few days later the user turns on notifications for your app again, at that point there may be notifications that the user no longer wants (since he/she deleted them from the UI) and some that have been expired already. How to find pending notifications that were deleted from the UI but not from the notification center in the event described above? FYI - I know how to delete pending notifications and how to compare notifications in the UI vs notifications in the notifications center. What I'm not sure about is when to do the comparison. Is there a way to get notified when the user turned back on notifications for your app so a method can be triggered to find orphan notifications? Thanks!
Posted
by fsdolphin.
Last updated
.
Post not yet marked as solved
1 Replies
264 Views
I can successfully connect and show ExternalView() on the external display on IOS target. However, mac catalyst is unable to detect the display connection in NotificationCenter. How do I use NotificationCenter in mac catalyst to detect and connect an external display? import Combine import SwiftUI @main struct ScreensApp: App {   @ObservedObject var externalDisplayContent = ExternalDisplayContent()   @State var additionalWindows: [UIWindow] = []   private var screenDidConnectPublisher: AnyPublisher<UIScreen, Never> {     NotificationCenter.default       .publisher(for: UIScreen.didConnectNotification)       .compactMap { $0.object as? UIScreen }       .receive(on: RunLoop.main)       .eraseToAnyPublisher()   }   private var screenDidDisconnectPublisher: AnyPublisher<UIScreen, Never> {     NotificationCenter.default       .publisher(for: UIScreen.didDisconnectNotification)       .compactMap { $0.object as? UIScreen }       .receive(on: RunLoop.main)       .eraseToAnyPublisher()   }   var body: some Scene {     WindowGroup {       ContentView()         .environmentObject(externalDisplayContent)         .onReceive(           screenDidConnectPublisher,           perform: screenDidConnect         )         .onReceive(           screenDidDisconnectPublisher,           perform: screenDidDisconnect         )     }   }   private func screenDidConnect(_ screen: UIScreen) {     print("connected")     let window = UIWindow(frame: screen.bounds)     window.windowScene = UIApplication.shared.connectedScenes       .first { ($0 as? UIWindowScene)?.screen == screen }       as? UIWindowScene     let view = ExternalView()       .environmentObject(externalDisplayContent)     let controller = UIHostingController(rootView: view)     window.rootViewController = controller     window.isHidden = false     additionalWindows.append(window)     externalDisplayContent.isShowingOnExternalDisplay = true   }   private func screenDidDisconnect(_ screen: UIScreen) {     print("disconnected")     additionalWindows.removeAll { $0.screen == screen }     externalDisplayContent.isShowingOnExternalDisplay = false   } }
Posted
by rakutek.
Last updated
.
Post not yet marked as solved
1 Replies
935 Views
We are entitled by Apple for critical alerts. Our app is an alerting app which shall now be used to alert deaf persons. We did not find the possibility to alert deaf persons, by choosing vibration instead of sound. The accessibility options of iOS don't seem to provide an option to choose vibration instead of sound. It does vibrate for a very short amount of time, but it must vibrate for at least 10-20 seconds to be of any help. Is there any possibility to vibrate upon receiving a critical alert notification for that amount of time? We're also using a notification service extension, but we're more interested in an official solution, than a "hack" solution.
Posted Last updated
.
Post not yet marked as solved
0 Replies
240 Views
I'm experiencing this weird problem where during development the following works flawlessly but is very flaky in production. I'm dynamically adding actions to notifications from my NotificationContent extension. When the user clicks on an action userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) should be called from where my app fires off an HTTP request based on the action that was selected. As already mentioned this works without issues during development but is extremely flaky in production. UNUserNotificationCenterDelegate: extension RealPushNotificationsHandler: UNUserNotificationCenterDelegate { func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) { completionHandler([.sound]) } func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { let userInfo = response.notification.request.content.userInfo if let actionPayload = userInfo["action"] as? String, let notificationUUID = userInfo["uuid"] as? String { // handleAction fires off an HTTP request handleAction(notificationUUID: notificationUUID, actionIdentifier: response.actionIdentifier, actionPayload: actionPayload, completionHandler: completionHandler) } } NotificationContent/NotificationViewController.swift: class NotificationViewController: UIViewController, UNNotificationContentExtension { override func viewDidLoad() { super.viewDidLoad() } func didReceive(_ notification: UNNotification) { var actions: [UNNotificationAction] = [] // Parse actions from notification.request.content.userInfo [...] // Append actions to notification extensionContext?.notificationActions = actions } }
Posted
by Timm1234.
Last updated
.
Post not yet marked as solved
0 Replies
194 Views
As far as I know it is easy to remove all pending notifications by just calling method      UNUserNotificationCenter.current().removeAllPendingNotificationRequests(), and to remove specific reminder we just add the hard coded identifier to the method removePendingNotificationRequests(withIdentifiers: "identifier"). But I'm not trying to remove all notifications or some with a hardcoded identifier. How can I remove a notification using a uuidString as the identifier which creates a unique identifier every time a user creates a new notification. I would like to delete the specific notification with the swipe delete style. If i could get a code sample i would really appreciate it. Here is my code where create my notification and where I would like to delete it: public var completionL: ((String,String,String)->Void)?       @objc func saveButtonPressed(){           if let titleText = titleTextFieldL.text, !titleText.isEmpty,       let bodyText = bodyViewField.text, !bodyText.isEmpty,       let searchText = locationSearchBar.text, !searchText.isEmpty{               completionL?(titleText,bodyText,"\(segmentedControl.titleForSegment(at: segmentedControl.selectedSegmentIndex)!): \(searchText)")               if segmentedControl.selectedSegmentIndex == 0{         if let center = defaults.coordinate(forKey: "NCoordinates"){           let content = UNMutableNotificationContent()           content.title = titleText           content.body = bodyText           content.sound = .default           let uuidStringEntry = UUID().uuidString           let region = CLCircularRegion(center: center, radius: 300.0, identifier: uuidStringEntry)           region.notifyOnEntry = true           region.notifyOnExit = false           let trigger = UNLocationNotificationTrigger(region: region, repeats: false)           let notificationRequest = UNNotificationRequest(identifier: uuidStringEntry, content: content, trigger: trigger)           UNUserNotificationCenter.current().add(notificationRequest) { error in             if error != nil{               print("Error providing Arriving notification")             }else{                              print("Successfully provided Arriving notification")             }           }         }       }else if segmentedControl.selectedSegmentIndex == 1{         if let center = defaults.coordinate(forKey: "NCoordinates"){                       let content = UNMutableNotificationContent()           content.title = titleText           content.body = bodyText           content.sound = .default           let uuidStringExit = UUID().uuidString           let region = CLCircularRegion(center: center, radius: 300.0, identifier: uuidStringExit)           region.notifyOnEntry = false           region.notifyOnExit = true           let trigger = UNLocationNotificationTrigger(region: region, repeats: false)           let notificationRequest = UNNotificationRequest(identifier: uuidStringExit, content: content, trigger: trigger)           UNUserNotificationCenter.current().add(notificationRequest) { error in             if error != nil{               print("Error providing Leaving notification")             }else{               print("Succesfully provided Leaving notification")             }           }         }       }             }         }     } Method to delete it:     return .delete   }       func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCell.EditingStyle, forRowAt indexPath: IndexPath) {     if editingStyle == .delete{       tableView.beginUpdates()       context.delete(reminder[indexPath.row])       reminder.remove(at: indexPath.row)              tableView.deleteRows(at: [indexPath], with: .fade)               tableView.endUpdates()       saveData()     }   }
Posted
by Chamoy.
Last updated
.
Post not yet marked as solved
1 Replies
440 Views
Is there a way to put code in iOS that is always watching in the background for the contact store to change? If I put it in my app, then the user can close the app, and the app won't receive notifications when the contact store changes? Is there an app extension I can use that would allow me to do this, whether that is the intent of the extension or not?
Posted Last updated
.
Post not yet marked as solved
2 Replies
331 Views
Dear random Apple UIKit engineer. This is a question for you. Today let's speak about keyboard notifications. In particular, UIResponder.keyboardWillShowNotification and UIResponder.keyboardWillHideNotification. While working with those, I noticed some undocumented behaviour. First, let me give you some context: extension UIViewController { func registerForKeyboardNotifications() { NotificationCenter.default.addObserver(self, selector: #selector(keyboardNotification), name: UIResponder.keyboardWillShowNotification, object: nil) NotificationCenter.default.addObserver(self, selector: #selector(keyboardNotification), name: UIResponder.keyboardWillHideNotification, object: nil) } /// Override this method to handle keyboard notifications. @objc func keyboardNotification(_ notification: Notification) { ... } } Eventually, I found that latter method with 3 dots has an implicit animation inside it's scope. Here is the [proof.](https://medium.com /uptech-team/why-does-uiresponder-keyboard-notification-handler-animate-10cc96bce372) Another thing I noticed, is that this property definition is perfectly valid let curve = UIView.AnimationCurve(rawValue: 7)!. The 7 btw comes from UIResponder.keyboardAnimationCurveUserInfoKey as a default value during my tests. So, the enum with 4 possible values (0...3) can be initialized with a value out of enum's cases range. Also, how can I initialize UIView.AnimationOption from 7? I will pollute my OptionSet which I feed to options parameter on UIView.animate(...) My questions: Why implicit animation is not documented and can I trust it or it's a subject to change. Why UIView.AnimationCurve(rawValue: 7)! does not crash. How can I convert UIResponder.keyboardAnimationCurveUserInfoKey's value into UIView.AnimationOption properly if I don't want to use implicit value. I don't encroach on UIKit secrets. I just need to know how to work with the API. Thank you!
Posted
by .Ev.
Last updated
.
Post not yet marked as solved
1 Replies
311 Views
Hi. I implemented a broadcast upload extension and it requests local notifications. The local notification works normally on broadcastStarted(withSetupInfo:), but the Banner of the local notification does not work on processSampleBuffer(_: with:) though its Notification Center works normally. What am I missing? Here is my code snippets. container app class AppDelegate: NSObject, UIApplicationDelegate { func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. requestAuthorization() ... } private func requestAuthorization() { let center = UNUserNotificationCenter.current() center.requestAuthorization(options: [.alert]) { granted, error in if let error = error { // Handle the error here. print(error) } if granted == true { center.delegate = self center.getNotificationSettings(completionHandler: { setting in print(setting) }) } else { print("not permitted") } } } } upload extension class SampleHandler: RPBroadcastSampleHandler { override func broadcastStarted(withSetupInfo setupInfo: [String : NSObject]?) { super.broadcastStarted(withSetupInfo: setupInfo) notification(title: "Upload Extension", body: "broadcastStarted") ... } override func processSampleBuffer(_ sampleBuffer: CMSampleBuffer, with sampleBufferType: RPSampleBufferType) { super.processSampleBuffer(sampleBuffer, with: sampleBufferType) ... if some condition { notification(title: "Upload Extension", body: "processSampleBuffer") } } private func notification(title: String, body: String) { let content = UNMutableNotificationContent() content.title = title content.body = body let request = UNNotificationRequest(identifier: UUID().uuidString, content: content, trigger: nil) let notificationCenter = UNUserNotificationCenter.current() notificationCenter.add(request) { error in if error != nil { print(error) } } } }
Posted
by y_ich.
Last updated
.
Post not yet marked as solved
0 Replies
631 Views
I want to add a category to my push notification and I can't seem to get any success in my attempts. I tried StackOverflow, but nobody responded, so I'm trying here. I thought it would be an issue with my Firebase Cloud Functions message payload, but it's not. I have a function to set a category on my notification when interacted with: func configureCategory() {     let viewAction = UNNotificationAction(identifier: "viewNewEvent", title: "View New Event", options: UNNotificationActionOptions.foreground)     let viewCategory = UNNotificationCategory(identifier: "newEventCategory", actions: [viewAction], intentIdentifiers: [], options: [])     UNUserNotificationCenter.current().setNotificationCategories(Set([viewCategory]))   } I then call this right before application.registerForRemoteNotifications() From, reading many articles, I thought this would work, but my notification just ends up with no actions when i receive it and interact with it. I even decided to create a UNNotificationServiceExtension, and add the identifier in that, but that didn't work either.  override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) - Void) {     self.contentHandler = contentHandler     bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)           if let bestAttemptContent = bestAttemptContent {              bestAttemptContent.title = "\(bestAttemptContent.title) [modified]"       bestAttemptContent.categoryIdentifier = "newEventCategory"               contentHandler(bestAttemptContent)     }   } If anybody knows how to do this properly and sees I'm missing something or placing something in the wrong spot, please point it out and let me know, thanks.
Posted Last updated
.
Post not yet marked as solved
0 Replies
188 Views
Hello,  in the guide for Notification & Focus it is written "Note: If you choose a setting from the “Show previews” pop-up menu at the bottom of the preference pane, it’s applied to all apps." (https://support.apple.com/de-de/guide/mac-help/mh40583/12.0/mac/12.3).) In fact, if i switch the global setting for "Show previews", e.g., to "when unlocked" this seems not to change anything for the installed apps. All apps preserve the individual setting configured under the their "Show previews" configuration dropdown, e.g., "always". The only thing which changes is, that the value in the app specific dropdown for "when locked" is extended by the string "(default)". This seems to rather add an indicator what the global setting is set to, then applying the global setting to all apps. Which makes no sense, since the system preferences menu can not be scaled that large that one would loose focus of the global settings right below.  So the behaviour of the global switch for “Show previews” differs from what I understand from the guide.  Is my understanding, the guide or the implementation wrong? Thanks, Joe
Posted Last updated
.
Post not yet marked as solved
0 Replies
251 Views
I'm trying to add GameKit support to my TodayWidget i make GKLocalPlayer.local.authenticateHandler but got error  [Account Error] startAuthenticationForExistingPrimaryPlayer:Failed to Authenticate player.Error: Error Domain=GKErrorDomain Code=15 "The requested operation could not be completed because this application is not recognized by Game Center." UserInfo={NSLocalizedDescription=The requested operation could not be completed because this application is not recognized by Game Center.} When i try do same request in Host App - it complete without any error. Any suggestion? Thanks
Posted
by DimasSup.
Last updated
.
Post not yet marked as solved
0 Replies
233 Views
Hello, I was trying to configuring rich notification for my app but then its became unable to install on my iphone after following the documentation for rich notification from braze, here is the link  : https://bit.ly/3uZqXKx This is the example of my xcode after add the notification service extension based on the documentation above : https://bit.ly/3BD98Cl And this is example when im try to install the app, after archive the build : https://bit.ly/3LDvNmh This is not happening before, but if i remove the notification extension from my xcode it will working as well as before, & if you guys curious if i am already do all the step from the documentation, the answer is i did. I am already set up the signing certificate, i am already add the code that the documentation given. FYI, if im running my app on debug mode using iphone simulator or iphone real device there is nothing happen its running well. The error unable to install happened after im archiving the app an export it into an .ipa file then install it to my iphone.
Posted Last updated
.
Post not yet marked as solved
0 Replies
209 Views
The problem of no local notifications coming on the first of January, February, April, June, August, September, and November has been going on for two years, ever since around iOS13. All of these months have one thing in common: the previous month has 31 days. Does anyone have the same problem, cause, or know how to fix it?
Posted
by toconakis.
Last updated
.
Post not yet marked as solved
1 Replies
717 Views
We read there is a focus mode introduced on iOS 15 https://www.apple.com/newsroom/2021/06/ios-15-brings-powerful-new-features-to-stay-connected-focus-explore-and-more/ The client ask us to enable this focus mode when we enter on a specific screen and disable this focus mode when we exit this screen, We want enable this focus mode to be not Disturbed by notification (No notification showing on the screen) enable/disable this mode programmatically Is this possible with this new feature ? Any help will be appreciate
Posted
by aqfdsdsf.
Last updated
.
Post not yet marked as solved
3 Replies
1k Views
My use case : i want the app to completely silence a given received alert push notification, based on information the app has locally (completely remove it, and never even display it. Not just change the sound or badge). So far i found no way of doing that : notification service extension doesn't let you remove the notification entirely, just change its content. Using "background / content" notification type then creating the notification locally doesn't work, since "background" notification type is unreliable by design. voip notifications are banned from being used as a general-purpose background notification mechanism since iOS13 Help would be greatly appreciated.
Posted Last updated
.
Post not yet marked as solved
0 Replies
166 Views
From iOS 15.1 version when ever a replaykit broadcast extension is running, the local notifications from UNUserNotificationCenter are not getting trigerred/fired. Note: Below iOS 15.1 everything seems fine Any solution to work around this issue or is it a bug from 15.1 version?
Posted Last updated
.
Post not yet marked as solved
0 Replies
175 Views
Hello, my apple AirPods are connected to my iPhone 13 through blue tooth but they won’t announce my notifications. I have reset my iPhone and have disconnected and reconnected my AirPods to my device. I have also made sure that “announce notifications” is on but my AirPods Pro still won’t read my messages. I’m able to listen to music through my headphones but Im just not able to get my AirPods Pro to read or my messages. Please help!
Posted Last updated
.