Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/c/56.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin (3D触摸)当用户关闭应用程序时,如何打开应用程序中的特定页面?_Xamarin_Xamarin.forms_Xamarin.ios - Fatal编程技术网

Xamarin (3D触摸)当用户关闭应用程序时,如何打开应用程序中的特定页面?

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) {

我正在使用导航到应用程序中的“搜索”页面

我在AppDelegate.cs:的方法performationforShortcutItem()中处理事件,单击快捷按钮:

    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 
        .....
    }