I am working on implementing one signal push-notification in Xamarin.forms. I am in need to pass the string returned for one-signal AdditionalData in App() constructor. So I used HandleNotificationOpened(OSNotificationOpenedResult result) for handling the notification tap and fetching the string and then passed it to LoadApplication(new App(myData)).
So for this I have written the code in MainActivity for android and in AppDelegate for ios. Everything is working fine for android i.e. the HandleNotificationOpened() fetched the additionalData and Load the application with this data.
But in iOS when I opened the notification, the HandleNotificationOpened() code is not called. I have tried many solutions.
AppDelegate.cs code:
static string s = null;
public override bool FinishedLaunching(UIApplication app, NSDictionary options)
{
OneSignal.Current.StartInit("MyKey").HandleNotificationOpened(HandleNotificationOpened).EndInit();
if(s!=null){
LoadApplication(new App(s));
}
else
{
LoadApplication(new App("myUrl.lasso"));
}
return base.FinishedLaunching(app, options);
}
private static void HandleNotificationOpened(OSNotificationOpenedResult result)
{
OSNotificationPayload payload = result.notification.payload;
Dictionary<string, object> additionalData = payload.additionalData;
if (additionalData != null)
{
if (additionalData.ContainsKey("url_direct"))
{
s = additionalData["url_direct"].ToString();
System.Diagnostics.Debug.WriteLine("We need to redirect it to: " + s);
}
}
}
Please help me with this issue it would be vry greatful. Thanks in advance