Questions tagged [unusernotificationcenter]

Manages the notification-related activities for your app or app extension. Local notifications and push notifications are both ways for an iOS application that isn’t running in the foreground to let its users know it has something for them. Use this tag for the queries related to the new Rich Notifications introduced in Swift 3.

Use the shared UNUserNotificationCenter object to schedule notifications and manage notification-related behaviors in your app or app extension. The shared user notification center object supports both local or remote notifications in varying capacities. Use this object to perform the following types of tasks:

  • Request authorization for displaying alerts, playing sounds, or badging the app’s icon in response to local or remote notifications. (Authorization is required for all user interactions.)

  • Declare the notification types that your app supports and the custom actions (if any) that the user may perform when those notifications
    are delivered.

  • Schedule the delivery of notifications from your app.

  • Manage app-specific notifications displayed in Notification Center.

  • Get the notification-related settings for your app.

The notifications that you schedule directly from your app are known as local notifications because your app creates them locally on the user’s device. By contrast, remote notifications are created by your own server and delivered to the user’s device via the Apple Push Notification Service (APNS).

370 questions
8
votes
4 answers

How to Unit Test locale-specific local notifications

I have just added local notifications to my app. These notifications are supposed to fire only if the app Locale's regionCode (i.e. Locale.current.regionCode) is "US" or "CA". I am not interested in the locale's language. I will also want to write…
Swifty
  • 839
  • 2
  • 15
  • 40
8
votes
0 answers

Swift - getDeliveredNotifications with completionHandler gives an empty array on first notification

I have this code: let center = UNUserNotificationCenter.current() func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping…
Marco
  • 1,051
  • 1
  • 17
  • 40
8
votes
2 answers

UNUserNotificationCenter didReceive response not called when app is terminated

I'm working on local notifications but the problem I have is that the method didReceive Response is not being called when the app is terminated so when I tap on a notification action it just launches the app and did nothing else. But when the app is…
techcoderx
  • 602
  • 1
  • 7
  • 21
7
votes
2 answers

How to cancel a local notification trigger in Swift

I have a trigger to show a notification to the user: let content = UNMutableNotificationContent() content.title = "Title" content.body = "Body" content.sound = UNNotificationSound.default let trigger =…
Chief Madog
  • 1,738
  • 4
  • 28
  • 55
7
votes
1 answer

Are silent remote push notifications deprecated in iOS 11?

Currently I'm able to receive silent push using app delegate's didReceiveRemoteNotification method. That method is deprecated and according to this we're supposed to be switching to UNUserNotificationCenter's willPresent method, but I can't seem to…
7
votes
2 answers

User Notification request always come with default action identifier

I am using the UNUserNotificationCenterDelegate (> ios 10) and one of the delegate methods where I can check the response from the notification has always actionIdentifier equal "com.apple.UNNotificationDefaultActionIdentifier" no matter what I do.…
user2116499
  • 403
  • 1
  • 5
  • 15
7
votes
1 answer

Add Custom Local Notification in ios10 - swift 3

I'm trying to add a custom local notification, but I'm only getting the stock notification with my action: My storyboard looks like this (standard template): I have a extension which has UNNotificationExtensionCategory set to awesomeNotification…
Bjarte
  • 2,167
  • 5
  • 27
  • 37
6
votes
4 answers

iOS 14 : UNUserNotificationCenter requestAuthorizationWithOptions always fails with "Notifications are not allowed for this application"

I could not find a solution for this and dumbfounded on this. I have this code : UNAuthorizationOptions authOptions = UNAuthorizationOptionAlert | UNAuthorizationOptionSound | UNAuthorizationOptionBadge; [[UNUserNotificationCenter…
user3570727
  • 10,163
  • 5
  • 18
  • 24
6
votes
1 answer

Detect if app was launched by opening a local notification on iOS10+

I am currently migrating an app to the new UserNotifications framework. I'm stuck at detecting if the app was launched due to the user opening a local notification. The test case is: Schedule a local notification Manually close the app Setup Xcode…
AXE
  • 8,335
  • 6
  • 25
  • 32
6
votes
0 answers

UNUserNotificationCenter notifications after device reboot

I have been searching online to see if the notifications that you have scheduled get deleted after the device reboots. I have found mixed opinions, so I've begun testing it. This is what I noticed: I have scheduled notifications in 10 minutes,…
6
votes
2 answers

Springboard crashing when adding a lot of triggers to UNUserNotificationCenter

Save yourselves from hours of debugging, because I've just wasted 2 weeks after bug hunting mysterious app crashes. It turns out, if you're adding a lot o (see answer for more details) notification requests to the UNUserNotificationCenter, it will…
strangetimes
  • 4,953
  • 1
  • 34
  • 62
6
votes
3 answers

Local notifications are not firing in ios10

I'm using UNUserNotificationCenter for ios 10. For testing, I'm setting a local notification for 10 seconds from current time. This is what I tried, - (void)viewDidLoad { [super viewDidLoad]; UNUserNotificationCenter *center =…
Nazik
  • 8,696
  • 27
  • 77
  • 123
6
votes
3 answers

How to handle UNNotificationAction when app is closed?

How to handle new iOS10 Notification Action when app is closed (not in background) ? when app is minimalized everything works fine with: UNUserNotificationCenter.current().delegate = x and handling it in class x: UNUserNotificationCenterDelegate { …
5
votes
1 answer

Unit testing for UNUserNotificationCenter .requestAuthorization in Swift 5

I am using test-driven development on Xcode and in Swift to develop an app. I want to add timed notification alerts to remind people to come back to the app to perform an action. To do that I need to request authorization from my user using the…
Kramer
  • 338
  • 2
  • 15
5
votes
0 answers

How do I decide which window to open Notification Settings in on iOS 13 for userNotificationCenter:openSettingsFor:?

iOS has the following method that gets called so you can offer custom notification settings to a user through Notification Center or the Settings app: func userNotificationCenter(_ center: UNUserNotificationCenter, openSettingsFor notification:…
1
2
3
24 25