question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Notifications when app is in foreground in iOS 10

See original GitHub issue

Please, add ability to show notifications when app is in foreground in iOS 10.

Example code:

// To receive notifications in foreground on iOS 10 devices.
[Export("userNotificationCenter:willPresentNotification:withCompletionHandler:")]
public async void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler)
{
    // Do your magic to handle the notification data
    System.Diagnostics.Debug.WriteLine("WillPresentNotification");

    // Tell system to display the notification anyway or use
    // `None` to say we have handled the display locally.
    completionHandler(UNNotificationPresentationOptions.Alert);
}

Thanks

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

5reactions
rdelrosariocommented, Aug 14, 2017

Planning on adding this in the next few days

2reactions
rdelrosariocommented, Sep 10, 2017

Just added this feature is available on: https://www.nuget.org/packages/Plugin.FirebasePushNotification/1.0.7-beta

Let me know your feedback guys and if satisfy your needs. Any suggestions are well received 😃

Here what I added on the docs:

iOS Specifics Customization

You can set UNNotificationPresentationOptions to get an alert, badge, sound when notification is received in foreground by setting static property FirebasePushNotificationManager.CurrentNotificationPresentationOption. By default is set to UNNotificationPresentationOptions.None.

     public enum UNNotificationPresentationOptions
	 {
	 	 Alert,	//Display the notification as an alert, using the notification text.
		 Badge,	//Display the notification badge value in the application's badge.
		 None,	//No options are set.
		 Sound  //Play the notification sound.
	 }

Usage sample on iOS Project:

   //To set for alert
   FirebasePushNotificationManager.CurrentNotificationPresentationOption = UNNotificationPresentationOptions.Alert;

   //You can also combine them
   FirebasePushNotificationManager.CurrentNotificationPresentationOption = UNNotificationPresentationOptions.Alert | UNNotificationPresentationOptions.Badge;

A good place to do this would be on the OnReceived method of a custom push notification handler if it changes depending on the notification, if not you can just set it once on the AppDelegate FinishLaunching.

Note: this feature is available from 1.0.7-beta version on.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Get push notification while App in foreground iOS
If your application is in foreground state, it means you are currently using the same app. So there is no need to show...
Read more >
Handling notifications and notification-related actions
If a notification arrives when your app is running in the foreground, the system delivers that notification directly to your app.
Read more >
How to show push notifications when my iOS app is in ...
How to show push notifications when my iOS app is in the foreground? Android and iOS handle push notifications differently when the app...
Read more >
Push Notifications by Tutorials, Chapter 8: Handling ...
For iOS to display your notification while your app is running in the foreground, you'll need to implement a UNUserNotificationCenterDelegate method, which is ......
Read more >
Handle Push notification during the App running in ...
1: First Set up firebase Push notification in App. · 2: Open Appdelegate. · 3: It will Check weather your app is running...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found