The Windows Phone 8.1 Preview SDK has been released for a few months now, and has written about several new features of Windows Phone 8.1, and today introduces you to the App Store launch protocol knowledge.
In this respect, we must have a lot of questions in mind, why the Windows Phone 8.0 era of Marketplacedetailtask, Marketplacereviewtask and Marketplacesearchtask are missing? This kind of problem appears on MSDN, StackOverflow and other websites many times, and I have answered similar questions on these websites many times.
Yes, it is. The SDK no longer provides us with this kind of class, but it needs to be implemented by the launch protocol: Windows.System.Launcher.LaunchUriAsync (URI uri).
Blog Park also has a classmate of the blog introduced this method of the specific implementation: Windows Phone 8.1 store launch protocol, here I do some additional, and then the several protocols similar to the Windows Phone 8.0 era of encapsulation.
1. Display the detailed information page for the specified product (marketplacedetailtask)
Start protocol: var uri = new Uri (string. Format ("ms-windows-store:navigate?appid={0}", AppID));
Here the AppId can be specified as Currentapp.appid, that is, to jump to the current application Detail page, or can be specified as a specific AppId, that is, to jump to a specific application Details page, this situation is used when the recommended application.
We do it in such a package:
using System;
using System.Threading.Tasks;
using Windows.ApplicationModel.Store;
namespace Windows.ApplicationModel.Tasks
{
public sealed class MarketplaceDetailTask
{
public MarketplaceDetailTask ()
{}
/// <summary>
/// Get or set the unique identifier of the product to be displayed.
/// </ summary>
public string ContentIdentifier {get; set;}
/// <summary>
/// Display the Windows Phone mall client application and display the details page for the specified product.
/// </ summary>
public async void Show ()
{
await Windows.System.Launcher.LaunchUriAsync (
new Uri (string.Format ("ms-windows-store: navigate? appid = {0}",
string.IsNullOrEmpty (ContentIdentifier)?
CurrentApp.AppId.ToString ():
ContentIdentifier)));
}
}
}
Call Method:
// Start the current application detail page by default
MarketplaceDetailTask task1 = new MarketplaceDetailTask ();
task1.Show ();
// launch specific application detail page
MarketplaceDetailTask task2 = new MarketplaceDetailTask ();
task2.ContentIdentifier = "some app id";
task2.Show ();
2. Display the comment page for the specified product (marketplacereviewtask)
Start protocol: var uri = new Uri (string. Format ("ms-windows-store:reviewapp?appid={0}", AppID));
The AppID here is set to the ID of the current app because it is unreasonable to comment on other apps in the app.
We do it in such a package:
using System;
using System.Threading.Tasks;
using Windows.ApplicationModel.Store;
namespace Windows.ApplicationModel.Tasks
{
public sealed class MarketplaceReviewTask
{
public MarketplaceReviewTask()
{ }
public async void Show()
{
await Windows.System.Launcher.LaunchUriAsync(
new Uri("ms-windows-store:reviewapp?appid=" + CurrentApp.AppId));
}
}
}
Call Method:
New marketplacereviewtask (); task. Show ();
3. Display Product Search page (marketplacesearchtask)
Start protocol: var uri = new Uri (string. Format (@ "ms-windows-store:search?keyword={0}", keyword));
The keyword here is the keyword we want to search for, and sometimes we need to search for all the apps for our developer account, so we can set keyword as the developer name. But if your developer name is similar to many products, such as the name: Weibo, then the search results will include the microblog app, not just the app in your "Weibo" developer name (well, a little Raozui). At this point we can change the keyword search to publisher search.
Based on the keyword and publisher two search methods, we do this encapsulation:
using System.Threading.Tasks;
using Windows.ApplicationModel.Store;
namespace Windows.ApplicationModel.Tasks
{
public sealed class MarketplaceSearchTask
{
public MarketplaceSearchTask(SearchTermsType type)
{
this.Type = type;
}
public string SearchTerms { get; set; }
public SearchTermsType Type { get; set; }
public async void Show()
{
await Windows.System.Launcher.LaunchUriAsync(
new Uri(string.Format("ms-windows-store:search?{0}={1}", this.Type.ToString() ,SearchTerms)));
}
}
public enum SearchTermsType
{
Keyword,
Publisher
}
}
Call Method:
// Search for all apps under ‘shaomeng’ developer name
MarketplaceSearchTask task1 = new MarketplaceSearchTask (SearchTermsType.Publisher);
task1.SearchTerms = "shaomeng";
task1.Show ();
// Search all apps that contain the keyword 'weibo'
MarketplaceSearchTask task2 = new MarketplaceSearchTask (SearchTermsType.Keyword);
task2.SearchTerms = "Weibo";
task2.Show ();
Okay, so here we have the usual App Store launch protocol. Hope to be able to help everyone. Windows Phone 8.1 "Pit" there are many, if you have other can not find the launch agreement, please leave a comment, I will continue to update, thank you.