Thursday, 31 October 2019

DidReceiveNotificationRequest in not getting called

I have a xamarin forms application and ios Notification service extension is not getting called when I receive notification from server.

I have done the following things so far:

  1. Have added the mutable-content = 1 in the apns payload.

  2. This is how I manipulate the apns payload in the service

    public class NotificationService : UNNotificationServiceExtension
    {
        Action<UNNotificationContent> ContentHandler { get; set; }
        UNMutableNotificationContent BestAttemptContent { get; set; }

        protected NotificationService(IntPtr handle) : base(handle)
        {

        }

        public override void DidReceiveNotificationRequest(UNNotificationRequest request, Action<UNNotificationContent> contentHandler)
        {
            ContentHandler = contentHandler;
            BestAttemptContent = (UNMutableNotificationContent)request.Content.MutableCopy();

            var newAlertContent = new UNMutableNotificationContent
            {
                Body = "Body from Service",
                Title = "Title from Service",
                Sound = BestAttemptContent.Sound,
                Badge = 2
            };
            ContentHandler(newAlertContent);
        }

        public override void TimeWillExpire()
        {
        }
    }
  1. I also have the the notification service extension bundle id done.(My app bundle id is com.companyname.appname.test and the extension bundle id is com.companyname.appname.test.xxxxServiceExtension

  2. In the AppDelegate class in Finishlaunching method I also have the permission code added.

  UNUserNotificationCenter.Current.RequestAuthorization(UNAuthorizationOptions.Alert, (approved, err) => {
            });

Is there anything else that I need to do?



from DidReceiveNotificationRequest in not getting called

No comments:

Post a Comment