创建Uri Scheme不启动应用程序Windows Phone

时间:2014-05-20 04:17:50

标签: c# windows-phone-8 uri-scheme

我按照here

步骤为我的应用创建了一个Uri方案

为了测试这个,我创建了另一个简单的应用程序来启动带有点击事件的原始应用程序

    private async void Button_Click(object sender, RoutedEventArgs e)
    {
        await Windows.System.Launcher.LaunchUriAsync(new System.Uri("startbackgroundwallpaper:"));
    }

在原始应用中,我有UriSchemeMapper

namespace StartBackgroundWallpaper
{
    class UriSchemeMapper : UriMapperBase
    {
        private string tempUri;

        public override Uri MapUri(Uri uri)
        {
            tempUri = System.Net.HttpUtility.UrlDecode(uri.ToString());

            // no parameters, desired launch to MainPage. no further code here.

            return uri;
        }
    }
}

我原始应用的InitializePhoneApplication() App.xaml.cs方法

      RootFrame.Navigated += CompleteInitializePhoneApplication;

        //Handle custom uri scheme
        RootFrame.UriMapper = new UriSchemeMapper();

现在,如果未安装原始应用,则在简单应用中引发Button_Click时,它会在搜索结果中正确列出。但是当它安装完毕后,loading...屏幕就会显示,但应用程序从未加载。

在应用WMAppManifest.xml中,我还添加了

<Extensions>
  <Protocol Name="startbackgroundwallpaper" NavUriFragment="encodedLaunchUri=%s" TaskID="_default" />
</Extensions>

我错过了什么?

2 个答案:

答案 0 :(得分:1)

我认为可能是因为你的URI没有返回任何内容。 我不知道你是否解决了你的问题,但如果没有,在你的UriSchemeMapper课程中,尝试更换你的行“return uri;”通过这个

return new Uri("/MainPage.xaml", UriKind.Relative);

不确定这是你的问题,希望有所帮助

答案 1 :(得分:0)

目前,您的映射器没有进行任何实际映射,因此您永远不会返回XAML页面以登陆用户。如果没有成功的初始导航,shell将显示加载屏幕,直到看门狗计时器启动并杀死您的应用程序。

Florian.C的答案很接近 - 对于通过URI方案启动的情况,确实需要返回对MainPage.xaml的引用。但是,一旦将UriMapper附加到RootFrame,就会为每个导航调用它。因此,您需要根据您的方案或应用中的其他导航来检查这是初始导航。

public override Uri MapUri(Uri uri)
{
     var tempUri = HttpUtility.UrlDecode(uri.ToString());

     if (tempUri.Contains("encodedLaunchUri=startbackgroundwallpaper"))
          return new Uri("/MainPage.xaml", UriKind.Relative);
     else
          return uri;            
}
相关问题