I am developing a simple spotlight extension on macOs. My app will index some content into spotlight. When I type some keywords, spotlight will trigger app's application:continueUserActivity:restorationHandler. And the application() will send a local notification. The code looks like this:
func application(_ application: NSApplication, continue userActivity: NSUserActivity, restorationHandler: ([NSUserActivityRestoring]) -> Void) -> Bool {
let notification = NSUserNotification()
notification.title = "title"
notification.subtitle = "subtitle"
notification.soundName = NSUserNotificationDefaultSoundName
NSUserNotificationCenter.default
.deliver(notification)
}
And I use macOs 10.14.3.
If my app does not running, and I type the keyword in spotlight, the spotlight will start my app and run the application(). And I will see the notification correctly.
However, if I type keyword again(my app is running background), the spotlight still tigger the application() method but the notification does not appeared. Even worse, I could see the notification in the notification center.
Anyone can make help? Thanks.
To be displayed separately, each notification mush have a unique identifier.
From the documentation (emphasis mine):
There are also limitations on how quickly you can post new notifications, so be aware of that.
Finally, if your'e developing for Mojave, you should probably be looking into
UNUserNotificationCenter, asNSUserNotificationCenteris deprecated.