DEV Community

Code Better #Sofast
Code Better #Sofast

Posted on • Edited on

3 1

[iOS] show notification banner when foreground run

Top comments (1)

Collapse
 
vominhhuy profile image
Code Better #Sofast • Edited

With iOS >= 10, you can show notification banner when app run foreground. To make it, you can add some line code in AppDelegate.m

//Called when a notification is delivered to a foreground app.
-(void)userNotificationCenter:(UNUserNotificationCenter *)center willPresentNotification:(UNNotification *)notification withCompletionHandler:(void ()(UNNotificationPresentationOptions options))completionHandler
{
completionHandler(UNAuthorizationOptionSound | UNAuthorizationOptionAlert | UNAuthorizationOptionBadge);
}

Don't forget, import UserNotification in head:

import

Hope it work with you.

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay