Xamarin (3D触摸)当用户关闭应用程序时,如何打开应用程序中的特定页面?
我正在使用导航到应用程序中的“搜索”页面 我在AppDelegate.cs:的方法performationforShortcutItem()中处理事件,单击快捷按钮:Xamarin (3D触摸)当用户关闭应用程序时,如何打开应用程序中的特定页面?,xamarin,xamarin.forms,xamarin.ios,Xamarin,Xamarin.forms,Xamarin.ios,我正在使用导航到应用程序中的“搜索”页面 我在AppDelegate.cs:的方法performationforShortcutItem()中处理事件,单击快捷按钮: public override void PerformActionForShortcutItem(UIApplication application, UIApplicationShortcutItem shortcutItem, UIOperationHandler completionHandler) {
public override void PerformActionForShortcutItem(UIApplication application, UIApplicationShortcutItem shortcutItem, UIOperationHandler completionHandler)
{
bool handledShortCutItem = HandleShortCutItem(shortcutItem);
completionHandler(handledShortCutItem);
}
- 在方法HandleShortCutItem()中,我向MainPageViewModel.cs发送MessagingCenter:
- 在MainPageViewModel.cs的Initialize()方法中,我订阅了上述MessagingCenter:
MessagingCenter.Subscribe(此,名称为(SearchContactEventMessage)),消息=>
{
//TODO在我的应用程序中打开页面搜索
.....
}
它的工作(可以打开“搜索”页面)时,我的应用程序运行前景或背景
如果我的应用程序无法打开或被用户杀死,则无法显示“搜索”页面
当用户“杀死”应用程序并使用“快速行动”时,我的应用程序可以在应用程序中显示特定页面。原因: 当用户在您的
MainPageViewModel.cs
中“kill”应用程序时单击并发送MessagingCenter
后,由于您的应用程序已终止,它尚未订阅MessagingCenter
。因此,将不会收到MessagingCenter
并在您的应用程序中打开页面搜索
解决方案:
我建议您直接在
handledShortCutItem
方法中打开搜索页面。但是AppDelegate.cs
的handledShortCutItem()方法。还有其他想法吗?我想打开一个可以查看Xamarin表单的页面。@BillNguyen您什么时候在MainPageViewModel.cs中订阅了MessagingCenter?如果您在应用程序打开后就订阅了,能否在HandleShortCutItem()中发送MessagingCenter之前再加一点延迟?哦,好主意,谢谢!这是工作时间(Mobile.App.IsInMainPage==false){wait Task.Delay(TimeSpan.FromSeconds(1)).configurewait(false);}```
MessagingCenter.Send(new SearchContactEventMessage(), nameof(SearchContactEventMessage));
MessagingCenter.Subscribe<SearchContactEventMessage>(this, nameof(SearchContactEventMessage), message =>
{
// TODO Open page Search in my app
.....
}