Forum Xamarin.Forms

Announcement:

The Xamarin Forums have officially moved to the new Microsoft Q&A experience. Microsoft Q&A is the home for technical questions and answers at across all products at Microsoft now including Xamarin!

To create new threads and ask questions head over to Microsoft Q&A for .NET and get involved today.

How to receive notification when app is open in ios

heli_shahheli_shah Member ✭✭
edited November 2020 in Xamarin.Forms

Hi,

I am working on xamarin.forms project. I am using fcm push notification approach and getting notification when app is close.
My requirement is to receive notification when app is open.

I have attached my AppDelegate.cs file here. Please let me know if anyone has any solution for this.

Thanks.

Answers

  • ColeXColeX Member, Xamarin Team Xamurai

    We need to override willPresentNotification method in AppDelegate , don't forget to export it with Selector Name .

    Sample code

    [Export("userNotificationCenter:willPresentNotification:withCompletionHandler:")]
            public virtual void WillPresentNotification(UNUserNotificationCenter center, UNNotification notification, Action<UNNotificationPresentationOptions> completionHandler) 
            {
                completionHandler(UNNotificationPresentationOptions.Badge| UNNotificationPresentationOptions.Sound);
            }
    
Sign In or Register to comment.