xamarin - (3D touch) 当用户杀死应用程序时,如何在应用程序中打开特定页面?
问题描述
我正在使用3D Touch 和快速操作导航到我的应用程序中的“搜索”页面。
我在AppDelegate.cs:的方法PerformActionForShortcutItem()处处理事件单击快捷方式按钮:
public override void PerformActionForShortcutItem(UIApplication application, UIApplicationShortcutItem shortcutItem, UIOperationHandler completionHandler)
{
bool handledShortCutItem = HandleShortCutItem(shortcutItem);
completionHandler(handledShortCutItem);
}
- 在方法HandleShortCutItem()中,我将MessagingCenter发送到MainPageViewModel.cs:
MessagingCenter.Send(new SearchContactEventMessage(), nameof(SearchContactEventMessage));
- 在MainPageViewModel.cs的Initialize()方法中,我订阅了上面的MessagingCenter:
MessagingCenter.Subscribe<SearchContactEventMessage>(this, nameof(SearchContactEventMessage), message =>
{
// TODO Open page Search in my app
.....
}
当我的应用程序在前台或后台运行时,它可以工作(可以打开“搜索”页面)。
如果我的应用程序未打开或用户将其杀死,则无法显示“搜索”页面。
当用户“杀死”应用程序并使用“快速操作”时,可以给我一个想法,我的应用程序可以在应用程序中显示某个页面。
解决方案
原因:
一旦您单击并发送MessagingCenter
当用户“杀死”应用程序时MainPageViewModel.cs
,它就没有订阅您的应用程序,MessagingCenter
因为您的应用程序已终止。因此,它不会MessagingCenter
在您的应用中接收和打开页面搜索。
解决方案:
我建议您直接在handledShortCutItem
方法中打开搜索页面。
推荐阅读
- python - 使用 csv.DictReader 和 os.listdir() 读取多个文件
- python - 遍历字典列表并与其他字典进行比较
- python-3.x - Pytest 使用装饰器模拟包含未传递的上下文管理器返回值的函数
- flutter - 为什么在使用 CustomPainter 时渐变会在整个屏幕上绘制?
- php - 通过 WooCommerce 订单和电子邮件中的文本更改特定运输方式的运输
- r - 用于计算 R 中功率的 2 个向量的 for 循环失败
- python - 如何访问 Pandas 中 nunique 给出的整数?
- c# - 如何在 vb.net 中声明函数以调用 c++ dll
- html - Safari (Webkit) 不正确地显示阴影(过滤器:drop-shadow)
- node.js - 如何使用 mongoimport 从导入的 json 数据中提取模式(或提取)?