(3D触摸)当用户杀死应用程序时如何在应用程序中打开特定页面?

时间:2019-05-13 14:18:06

标签: xamarin xamarin.forms xamarin.ios

我正在使用3D Touch and Quick Actions导航到应用程序中的“搜索”页面。

我处理事件,方法是单击 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 
        .....
    }

当我的应用程序运行在前台或后台时,它可以正常工作(可以打开“搜索”页面)。

如果我的应用无法打开或被用户杀死,则无法显示“搜索”页面。

当用户“杀死”应用程序并且使用“快速操作”时,可以给我一个想法,我的应用程序可以在该应用程序中显示某个页面。

1 个答案:

答案 0 :(得分:1)

原因:

当用户“杀死”应用程序时,单击并发送MessagingCenter后,您MainPageViewModel.cs中的用户就没有订阅MessagingCenter,因为您的应用程序已终止。因此,它不会在您的应用中收到MessagingCenter和打开页面搜索。

解决方案:

我建议您直接使用handledShortCutItem方法打开搜索页面。