Show iOS notification when app is running

During our last competence activity we took a look at iOS notification. There has been some changes and a few new things added in iOS 10. To learn what is new I recommend to see the wwdc videos about notification. I did also watch some videos on YouTube and read some blog posts, links below.

My simple lab can be found here on GitHub. There is a solution branch where you can find a solution. There is also a powerpoint in there but it mostly contains the links above. Look at how the first example works and then try to solve the others.

Now back to the title. During the lab we discussed a lot of thing but one thing stood out, show notification when app is running. Many said this has been difficult in the past and all kind of workaround has been tried to solve this. To get this going one need to set UNUserNotificationCenter.current().delegate = self in didFinishLaunchingWithOptions. I did it in the AppDelegate.swift but I guess it can be set in any view.

This is not enough. You also need to tell the notification what to do with it when you get it. This is done in the extension part, also in AppDelegate.swift.

This will make the notification show when the app is running.

Happy coding

Leave a Reply