iosswiftusernotifications

UserNotifications related events


I am working with an iOS app using UserNotifications.

When the user taps on a notification, this method is fired:

userNotificationCenter(_:didReceive:withCompletionHandler:)

I want to know if there is a method called when the notification arrives, independently of when the user reacts.


Solution

  • Yes you can : https://developer.apple.com/documentation/usernotifications/unusernotificationcenterdelegate/1649518-usernotificationcenter Of course the app has to be open for that. you can not execute code if the app is closed. In some cases you can execute code if the app is in background but that required special authorisation.