Buy a simulated application
You can useWindowsstoreproxy. xmlModify the user interface based on whether the application is a trial version. However, the actual purchase behavior cannot be simulated. In this exercise, you need to write an event for the purchase button.ProgramIn this way, you canWindowsThe app is purchased in the app store.
Task1-InAbout. jsAdd purchaseCode
To simulate the purchase behavior of an application, we need to callCurrentappsimulator. requestapppurchaseasync. To check the successful arrangement of purchase behaviors, we need to handleLicensechangedEvent.
Note:RequestpurchaseappasyncMethod to submit a slaveWindowsThe app store purchases the app's asynchronous request. To determine when (whether) the application is successfully purchased, you need to listenLicensechangedEvent. When this event is triggered, you can checkCurrentappsimulator. licenseinformation. istrialTo confirm whether the purchase is successful.
1.OpenAbout. js.
2.In theIf (App. licenseinformation. istrial)At the end of the clauseElseBefore the statement, add the following statement:
Javascript
// Handle licensechanged events
App. licenseinformation. onlicensechanged = function (){
If (! App. licenseinformation. istrial ){
VaR dialog = newwindows. UI. popups. messagedialog ("Thanks for purchasing contosocookbook! ");
Dialog. showasync ();
}
};
// Handle clicks of the purchase button
Button. onclick = function (){
App. requestapppurchaseasync ();
};
Task2-Purchase applications
Simple, right? Now simulate the purchase behavior of the application. Please note that,CurrentappsimulatorStore the purchase and license status modification information in the memory, and do not store the information inWindowsstoreproxy. xml. Therefore, after purchasing an application, as long as the application is still running,Purchased(Paid) "status, and once restarted, It is restored to the trial version status.
1.PressF5Enable the application.
2.Open"About"Page, click the Buy button to simulate the application purchase behavior.
3.InWindowsIn the App Store dialog box, click"Continue"Button to complete the simulated purchase behavior.
4.Confirm3Confirm that the purchase is successful.
Figure3
Message confirming successful purchase
5.Display"About"Page, confirm that the purchase button has disappeared.
Note:Before purchasingContosocookbookLater, it does not provide additional features for users; it just uses license information to replace the purchase button. In real-world applications, you can select to restrict user functions in the trial version. The full function is provided only after the purchase.
6.ReturnVisual StudioAnd stop debugging.
Note: ThisArticleThis is the script for Windows 8 online lab on msdn. It is for your reference only. If you want to experience the complete experiment, click the msdn online lab below
Http://msdn.microsoft.com/zh-cn/hh968278