为了账号安全,请及时绑定邮箱和手机立即绑定

如果在打开通知之前关闭应用程序,则不会处理 HandleNotificationOpened

如果在打开通知之前关闭应用程序,则不会处理 HandleNotificationOpened

C#
慕妹3146593 2023-09-24 15:43:38
如果应用程序在后台或正在运行,HandleNotificationOpened 工作正常,但如果我在应用程序关闭时打开通知,则不会触发它。我尝试使用 SecureStorage 保存事件中的数据,因为我不确定事件是否在错误的时间运行,或者根本不运行。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");    }}预期结果是应用程序正确处理事件,根本没有错误消息。
查看完整描述

2 回答

?
Helenr

TA贡献1780条经验 获得超3个赞

当应用程序关闭时,不会调用此方法。

虽然我没有使用OneSignal来推送通知,但是根据Android/iOS系统通知处理机制,当app关闭时,当收到远程通知时,点击通知会重启app,通知处理机制是通过系统托盘。

所以该HandleNotificationOpened方法不会被调用。


查看完整回答
反对 回复 2023-09-24
?
暮色呼如

TA贡献1853条经验 获得超9个赞

我已经使用 URI 方案来访问早期初始化后台数据解决了这个问题,用自定义格式化方法替换了 方法HandleNotificationOpenedIntent?.Data?.EncodedQuery;这就是我得到预期结果的方式。



查看完整回答
反对 回复 2023-09-24
  • 2 回答
  • 0 关注
  • 65 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信