Make multiple NSUserNotifications (and their action) buttons perform separate actions

368 Views Asked by At

I've been learning Swift at my own pace, and I've dived into notification buttons, and making them do things, after learning how to make NSUserNotifications.

I know how to make a single notification's action button perform an action by using the below in AppDelegate.swift

func userNotificationCenter(center: NSUserNotificationCenter, didActivateNotification notification: NSUserNotification) 
{
  print("You clicked the notification button!")
}

The question is, how do I make a second one do the same? I've searched high and low for an easy-to-understand answer here on SO, reddit, and via numerous Swift tutorial websites before I asked this question, as while delegates and overriding are no problem for me in C#, and I get the concept, I'm completely at a loss in Swift how to do this.

Thought Process

Because didActivateNotification notification: NSUserNotification" in AppDelegate.swift contained the identifier "notification", which was also the identifier for my first NSUserNotification object in my ViewController class, if I declared userNotificationCenter() again, and changed "didActivateNotification notification: NSUserNotification" to "didActivateNotification notif: NSUserNotification", for my second NSUserNotification object with the identifier 'notif', it should execute the relevant actions for my second notification's action button, which was printing a slightly different message to the console, right?

Needless to say, it didn't work.

What I did in terms of UI

I had two buttons, each of which generated a notification with different text, and action buttons which would (supposedly) do different things.

Wrapping up

So, what would I need to do to have two (or more) notifications' action buttons perform their respective actions?

Any help is very gratefully received, and thanked for in advanced.

0

There are 0 best solutions below