如何使用 .NET 代码从 Windows Phone Marketplace 获取我的应用程序的深层链接? [英] How to get a deep link of my application from the Windows Phone Marketplace using .NET code?

查看:13
本文介绍了如何使用 .NET 代码从 Windows Phone Marketplace 获取我的应用程序的深层链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式从 Windows Phone Marketplace 获取我的应用程序的深层链接,以便我可以在我的代码中使用它?

How do I get a deep link of my application programmatically from the Windows Phone Marketplace, so that I can use it in my code?

推荐答案

获取 AppDeeplink 非常有用,例如在 ShareStatusTask 和 ShareLinkTask 中.
这是可能的,但是您必须使用一些重要的代码来从您的应用程序清单文件中获取真正的 AppID.这就是我所做的:
首先在资源中保存 Windows Phone 应用程序深层链接的字符串,这很简单:

Getting the AppDeeplink is quite useful for example in ShareStatusTask and ShareLinkTask.
It is possible, however you have to use some non-trivial code for getting the real AppID from within your app Manifest file. Here's what I do:
First save somewhere in resources the string for Windows Phone app deeplinks, this is simple:

"http://windowsphone.com/s?appId={0}"

"http://windowsphone.com/s?appId={0}"

然后您必须通过打开 App Manifest 文件并找到正确的标签来找到真正的 AppId,我在 MarketplaceHelper 中使用此代码来执行此操作:

Then you have to find the real AppId by opening the App Manifest file and finding the proper tag, I use this code inside my MarketplaceHelper for doing so:

static MarketplaceHelper()
{
    try
    {
        // load product details from WMAppManifest.xml
        XElement app = XElement.Load("WMAppManifest.xml").Descendants("App").Single();

        Title = GetValue(app, "Title");
        Version = new Version(GetValue(app, "Version"));
        Author = GetValue(app, "Author");
        Publisher = GetValue(app, "Publisher");
        Description = GetValue(app, "Description");

        // remove the surrounding braces
        string productID = GetValue(app, "ProductID");
        ProductID = Regex.Match(productID, "(?<={).*(?=})").Value;
    }
    catch (Exception e)
    {
        // should not happen, every application has this field and should containt the ProductID and Version
    }
}

private static string GetValue(XElement app, string attrName)
{
    XAttribute at = app.Attribute(attrName);
    return at != null ? at.Value : null;
}

如果 Manifest 存在并且格式正确,它应该是,否则应用程序将无法运行,您可以通过这种方式获取您想要的任何数据.

If the Manifest is there and is properly formatted, and it should be, otherwise the app won't work, you can get this way any data you want.

现在你可以像这样构建深层链接:

Now you can construct the deeplink like this:

string deeplink = string.Format(AppResources.DeepLinkFormat, MarketplaceHelper.ProductID);

这篇关于如何使用 .NET 代码从 Windows Phone Marketplace 获取我的应用程序的深层链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆