CrossGeeks / AzurePushNotificationPlugin

Azure Push Notification Plugin for Xamarin iOS and Android
MIT License
67 stars 34 forks source link

Notifications not being displayed if app is in the foreground on iOS #22

Closed RickB864 closed 4 years ago

RickB864 commented 5 years ago

I have a xamarin forms ios app. When the app is in the foreground, the notification is not displayed, otherwise it is display. However, when the app is in the background and the notification is received tapping the "See More" opens the app and then opens the URL in a browser. I'd like to not open the app and just send the user to the URL. I've tried default as the action type, but that just closes the notification.

FinishedLaunching

`AzurePushNotificationManager.Initialize( Global.PushNotificationsHubEndpoint, Global.PushNotificationsHubName, options, new NotificationUserCategory[] {new NotificationUserCategory("link",new List { new NotificationUserAction("close","Dismiss",NotificationActionType.Default), new NotificationUserAction("open","See More",NotificationActionType.Foreground)})}, true);

CrossAzurePushNotification.Current.OnNotificationOpened += (s, p) => { if (!string.IsNullOrEmpty(p.Identifier)) { if(p.Identifier.ToLower() =="open") { foreach (var data in p.Data) { if (data.Key == "aps.url" && data.Key.ToString().Length > 0) { UIApplication.SharedApplication.OpenUrl(new Uri(data.Value.ToString())); } } }

            }

        };

...

public override void DidReceiveRemoteNotification(UIApplication application, NSDictionary userInfo, Action completionHandler) {

        AzurePushNotificationManager.DidReceiveMessage(userInfo);
    }

public override void RegisteredForRemoteNotifications(UIApplication application, NSData deviceToken) { try { AzurePushNotificationManager.DidRegisterRemoteNotifications(deviceToken);

        }
        catch (Exception)
        {

            //Global.GALogException(ex, "RegisteredForRemoteNotifications");
        }
    }

`

HectorOCH commented 5 years ago

Insert this code in the notification (IOS only)

 "aps" : {
        "content-available" : 1
    }