如果在我打开通知之前关闭了应用程序,则不会处理HandleNotificationOpened [英] HandleNotificationOpened are not handled if app is closed before i open the notification
问题描述
如果App在后台运行或正在运行,HandleNotificationOpened可以正常工作,但是如果我在应用关闭时打开通知,则不会触发.
HandleNotificationOpened is working perfectly if App is on the background or running but it's not fired if i open the notification when app is closed.
我已尝试通过SecureStorage保留事件中的数据,因为我不确定事件是否在正确的时间运行,或者是否在错误的时间运行.
I've tried to persist the data from event with SecureStorage, because i'm not sure if the event run but in the wrong time or it doesn't run at all.
public App()
{
OneSignal.Current.StartInit("onesignal-id").HandleNotificationOpened(HandleNotificationOpened).HandleNotificationReceived(HandleNotificationReceived).EndInit();
}
private async void HandleNotificationOpened(OSNotificationOpenedResult result)
{
var data = result.notification.payload.additionalData;
if (data != null)
{
data.TryGetValue("Title", out object Title);
data.TryGetValue("Conteudo", out object Conteudo);
data.TryGetValue("Link", out object RLink);
string lastvar = (Title.ToString().GetHashCode() + Conteudo.ToString().GetHashCode() + RLink.ToString().GetHashCode()).ToString();
if (!ChecarDB(lastvar))
{
InserirDB(Title.ToString(), Conteudo.ToString(), RLink.ToString());
}
await SecureStorage.SetAsync("UrlFromPush", RLink.ToString());
var page = new MainPage();
MessagingCenter.Send<MainPage>(page, "MudarURL");
}
}
预期结果是应用程序正确处理了事件,根本没有错误消息.
Expected result is the application properly handle the event, No error messages at all.
推荐答案
我已经使用URI方案访问了早期初始化背景数据,使用自定义格式方法将Intent?.Data?.EncodedQuery;
的HandleNotificationOpened
方法替换为Intent?.Data?.EncodedQuery;
,从而解决了此问题我得到了预期的结果.
I've solved this issue using URI Scheme to access early init background data, replacing the HandleNotificationOpened
method for Intent?.Data?.EncodedQuery;
with custom formatting method, that's how i got the expected result.
这篇关于如果在我打开通知之前关闭了应用程序,则不会处理HandleNotificationOpened的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!