Windows Phone 7 Development talk on the 31st day-23rd: provides a trial application

Source: Internet
Author: User

This article is the 23rd day of the "Windows Phone 7 development on the 31st day" series.

Yesterday, I wrote about how to add a game to the phone's game center. Today, I will show youProgramHow easy it is to add trial content. For example, suppose you have created a 50-level game. Maybe you want users to experience the first 5 levels for free, but they need to purchase the game if they want to play the back. This article shows you how to do this.

Use the licenseinformation class

By adding a Microsoft. Phone. marketplace assembly and corresponding namespace to our page, you can access the licenseinformation class, which is directly related to the "Payment" Status of the program.

Using Microsoft. Phone. marketplace;

The next step is to use the licenseinformation class to create an instance:

Licenseinformation Li =   New Licenseinformation ();

Finally, licenseinformation has a very good method to return a Boolean value called istrial (). There is no suspense that it allows us to check whether the program is in trial status. You can easily use it for an if statement, like this:

If ( ! Li. istrial ())
{
// Do something that only paid users can do.
}
Else
{
// Do something that all users, trial or paid, can do.
}

Test Mode

Unfortunately, there is no built-in mechanism for switching between trial and paid statuses. However, this process is simple. I used the same if statement in the app. XAML. CS file. Use it to check whether you are debugging. If yes, create an isolatedstoragesetting called "trialmode.

The following describes the entire app () method, including the automatic generation of the app. XAML. CS file.Code. In the following example, I set trialmode to true. Disable the "paid" mode when you test it.

Code Isolatedstoragesetemedisettings = Isolatedstoragesettings. applicationsettings;

PublicAPP ()
{
//Global handler for uncaught exceptions.
Unhandledexception+ =Application_unhandledexception;

Settings ["Trialmode"]= False;

// Show graphics profiling information while debugging.
If (System. Diagnostics. Debugger. isattached)
{
Settings [ " Trialmode " ] =   True ;

// Display the current frame rate counters.
Application. Current. Host. settings. enableframeratecounter =   True ;

// show the areas of the app that are being redrawn in each frame.
// application. current. host. settings. enableredrawregions = true;

// enable non-production analysis visualization mode,
/// which shows areas of a page that are being GPU accelerated with a colored overlay.
// application. current. host. settings. enablecachevisualization = true;
}

//Standard Silverlight Initialization
Initializecomponent ();

//Phone-specific Initialization
Initializephoneapplication ();
}

Looking back at the previous code, I need to modify the if statement to process this new isolatedstoragesettings value. This time I included the entire mainpage. XAML. CS file, so you can see all the content in combination with the context.

Code Using System;
Using System. Collections. Generic;
Using System. LINQ;
Using System. net;
Using System. windows;
Using System. Windows. controls;
Using System. Windows. documents;
Using System. Windows. input;
Using System. Windows. Media;
Using System. Windows. Media. animation;
Using System. Windows. shapes;
Using Microsoft. Phone. controls;
Using Microsoft. Phone. marketplace;
Using System. Io. isolatedstorage;

Namespace Day23_usingtrial
{
Public   Partial   Class Mainpage: phoneapplicationpage
{
Licenseinformation Li =   New Licenseinformation ();
Isolatedstoragesetemedisettings = Isolatedstoragesettings. applicationsettings;

// Constructor
Public Mainpage ()
{
Initializecomponent ();

If ( ! Li. istrial () | ( Bool ) Settings [ " Trialmode " ] =   False )
{
// Do something that only paid users can do.
}
Else   If (Li. istrial () | ( Bool ) Settings [ " Trialmode " ] =   True )
{
// Do something that all users, trial or paid, can do.
}
}
}
}

This is all you need to do. Of course this is not the "best" way to solve this problem, but it does work for me. If anyone has any good method, I would like to use it.

Download Sample Code

You can use a running example to view all the above content, download this solution and study it. This is always a good way to learn.

Address: http://www.jeffblankenburg.com/post/31-Days-of-Windows-Phone-7c-Day-23-Providing-Trial-Versions-of-Your-App.aspx

If you like myArticle, Please click "recommended ",Thank you!

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.