Published articles on other web sites*

Published articles on other web sites*

Creating a Windows Phone 7 Trial Application: Implementation and Best Practices

I am starting a "Creating a Windows Phone 7 Trial Application" series of three posts in which I will cover all about creating a trial app in Windows Phone 7:
In this post I am going to talk about building a Windows Phone 7 Trial application and some best practices. I will focus on some important thing that you need to consider when implementing a trial mode like: why you have to cache the trial state, Top 5 things to consider when building Trial app, different techniques, debugging trial mode etc. I will also give some examples of incorrect trial mode implementations that I found on the web.
To begin with, basically Trial mode gives you the option to allow users to try your application before buying it. The Windows Phone platform enables developers to easily add a configurable Trial capability to their application. When submitting your WP7 application to the Windows Phone Marketplace you can choose whether to allow trial licenses for the applications that you submit. Just check the Trial Application box and Windows Phone Marketplace will display a Try option view on the application detail page. The trial license does not expire, but is replaced by a full license when the customer purchases the application.
Create a WP7 Trial app in 7 Steps

Implementing Trial mode in a Windows Phone 7 application is actually pretty easy thanks to theMicrosoft.Phone.License.LicenseInfo class which exposes the IsTrial() method. The method does exactly what its name says- it returns a bool value indicating whether the application is running in a trial mode(True if in Trial otherwise False). However there are lost of important things you need to consider if you want to pass the certification requirements and build a user friendly Trial app.
Here are our suggestions for creating a fully functional WP7 Trial app presented in 7 steps:
Step 1Consider!: Have in mind that when implementing Trial mode you have to consider lots of things like Application Lifecycle and Tombstoning ,  back button, performance, etc. Here is how the full proses with all cases should look like:
89-04png
NOTE: For more info about WP7 Application Lifecycle and Tombstoning take a look at our article: WP7 Application Lifecycle and Tombstoning
For performance consideration it is important to "Cache" the state of the  IsTrial()! A typical call to IsTrial()  takes approximately 60 milliseconds. So if you call this method regularly(every time when you need to check if your app is in trial more) as a result this will lead to bad performance of your application.  In the worst case your application can even fail certification.
Step 2: Create a static bool property in App.xaml.cs for Caching the trial state.
Use a static property for caching and easy access to the trial state. For example IsTrial property created in App.xaml.cs with private setter so that we are sure that setting the IsTrial property from outside is not allowed:
public static bool IsTrial
{
    get;
    // setting the IsTrial property from outside is not allowed
    private set;
}

Step 3:  Determine if the app is in Trial state
Create a method in App.xaml.cs that check the value of the  Microsoft.Phone.Marketplace.LicenseInformation IsTrial() method. I.e. determine whether the app is in Trial mode or not (True if in Trial otherwise False). Note that we will return true if debugging with trial enabled (DebugTrial configuration is active: see the Debugging Trial App section below!) :
private void DetermineIsTrail()
{
#if TRIAL
    // return true if debugging with trial enabled (DebugTrial configuration is active)
    IsTrial = true;
#else
    var license = new Microsoft.Phone.Marketplace.LicenseInformation();
    IsTrial = license.IsTrial();
#endif
}
NOTE:  If you are running the application while developing (in the emulator), then IsTrial() will always return FALSE.  A workaround of this issue is to hard code the method to return TRUE  when debugging as demonstrated above.
Step4: Cache/Refresh IsTrial() on the right place!
The most important thing you must do is to "refresh"  the state of the  IsTrial() on the right place:
  • refresh the value of the IsTrial property when the application is launched - Application_Launching handler
  • refresh the value of the IsTrial property when the application is activated - Application_Activated handler
// Code to execute when the application is launching (eg, from Start)
// This code will not execute when the application is reactivated
private void Application_Launching(object sender, LaunchingEventArgs e)
{
    // refresh the value of the IsTrial property when the application is launched
    DetermineIsTrail();
}

// Code to execute when the application is activated (brought to foreground)
// This code will not execute when the application is first launched
private void Application_Activated(object sender, ActivatedEventArgs e)
{
    // refresh the value of the IsTrial property when the application is activated
    DetermineIsTrail();
}
NOTE: It is very important not to forget to Cache IsTrial() when the app is launched  and activated otherwise you app will not work correctly in all cases like: tombstoning, back button, terminated app, etc.
So in short here is what you will need to add in App.xaml.cs:
public static bool IsTrial
{  get;    private set;}

private void DetermineIsTrail()
{
#if TRIAL
    IsTrial = true;
#else
    var license = new Microsoft.Phone.Marketplace.LicenseInformation();
    IsTrial = license.IsTrial();
#endif
}

private void Application_Launching(object sender, LaunchingEventArgs e)
{
    DetermineIsTrail();
}

private void Application_Activated(object sender, ActivatedEventArgs e)
{
    DetermineIsTrail();
}

Step 5: Define logic for Trial and Full modes
This approach enables you to easily determine the current app Trial state in all parts of the application without worrying about the performance. All you need to do is just to call the previously created static IsTrial property in App.xaml.cs:
if (App.IsTrial)
{
    //add trial code here
}
else
{
    //add full code here
}
Step 6:  Implement Buy Now  functionality
We will discuss this section in depth in the Part2 of this article: Creating a Windows Phone 7 Trial Application |Part2: Adding Buy Now Functionality
Step7: Test your Trial app
This topic is cover in the next section: Debugging your WP7 Trial App
Common Mistakes when implementing a WP7 Trial app
While I was browsing the net to look for another interesting approaches I was really unpleasantly surprised how many incorrect articles related to the WP7 Trial apps are published. Here are some of the most common mistakes that I found:
Mistake 1: Assigning the value of IsTrial to a static variable, but forget to refresh on Launching and Activated events!
Mistake 2: In most of the posts the authors do not even mention something about tombstoning and Launching/Activated  handlers(Note you need understand the whole Trial App process from the Start to Finish and consider all possible cases).
Mistake 3: Calling  Microsoft.Phone.Marketplace.LicenseInformation IsTrial() method multiple times. I.e. do not use any kind of Caching which immediately leads to a bad performance.
Mistake 4: In some implementations Testing and Debugging are missing. Although it may be possible to submit a Trial app without testing it, this is a bad practice and should be avoided.
NOTE: So my advice is if you have any doubts about implementing WP7 Trial app just take a look at the official MSDN Documentation: Execution Model Overview for Windows PhoneTrial Applications Overview for Windows Phone
Debugging your WP7 Trial App
Testing is something very important. As I mentioned previously, although it may be possible to submit a Trial app without testing it, this is a bad practice and should be avoided!
If you are running the application while developing (in the emulator), then IsTrial() will always return FALSE.  A workaround of this issue is to hard code the method to return TRUE when debugging using Preprocessor Directives (#if TRIAL ).
Another thing you need to do is to change the current configuration of your project. Here is how to do this in 6 steps:
Step1: Create a Windows Phone 7 Application Project and select Configuration Manager option. :
89-0
Step2: As a result of Step1 a new Configuration Manager Window appears. Go to Active Solution Configuration combo and select New:
89-1
Step3: Name the new configuration for example "DebugTrial" and select "Debug" option under Copy settings from:
89-01
Press OK and you will see the updated project details in Configuration Manager:
89-3
Step4:  Close the Configuration Manager windows. Go to your Project root in Visual Studio  Solution Explorer and Right Click on your Project then select Properties:
89-4
Step5: Go to Build tab. In the Configurations combo select the newly created configuration "DebugTrial" from Step3. Next add an additional "TRIAL" symbol in the Conditional compilation symbols TextBox:
89-00
Step 6: That's it. Now you are ready to debug and test. Just select the newly created "DebugTrial " Configuration.
89-05
Here is how we determine whether the app is in Trail mode or not(This is explained in  the above sections "Create a Trial app in 7 Steps" as well):
private void DetermineIsTrail()
{
#if TRIAL
    // return true if debugging with trial enabled (DebugTrial configuration is active) 
    IsTrial = true;
#else
    var license = new Microsoft.Phone.Marketplace.LicenseInformation();
    IsTrial = license.IsTrial();
#endif
}
Top 5 things to consider when building a Trial app
To summarize, here are the top 5 things to consider when implementing Trial mode:
  • 1. Trial License expiration. When a user tries your application, a trial edition is installed on their phone. An edition with a trial license does not expire, but when a user purchases an application they are trying, a full license is downloaded and replaces the trial license associated with the installed edition.
  • 2. Check the IsTrial() state when your application loads or resumes. Your application can use the IsTrial() method of theLicenseInformation class to determine the kind of license that is in place.   This method returns true if the application is running under a trial license, and it returns false if the application has been purchased and is running under a full license.
Note:Cache license state if you check trial state frequently. Note that the IsTrial() and the Guide.IsTrialMode methods are designed to be event-driven. A typical call takes approximately 60 milliseconds or more.
Note:If you are running the application while developing (in the emulator, for example), then IsTrial() will always return FALSE.  You can get around this by hard-coding the method to return TRUE when debugging.
  • 3. Provide a way for users to buy your trial application before the end-of-trial.   You can include an element in your application that allows a trial user to purchase your application through the Windows     Phone Marketplace by calling the Show() method of the MarketplaceDetailTask class.
  • 4. Do not rely on usage time limited trials to protect your application's value.
    Typically, it is best to protect the value of your full mode application by limiting trial access to key code paths. A user may uninstall and retry an application without restriction so a trial design that offers full mode behavior for a limited time provides only inconvenience as a barrier to reuse.
  • 5. Trial Mode Testing
    XNA Framework applications should use the Guide class in the GamerServices namespace to differentiate Trial and Full mode behavior and provide a purchase path for their Games. For more information, see Simulating Trial Mode for Marketplace Content.
Why adding Trial mode to your app?
Here is what the windows phone 7 development team posted a while ago regarding the use of a Trial option for pay apps in the marketplace:
Our theory when building this capability was that more users would consider and buy apps if they could try the app out first to see if they like it. Results?
  • Users like trials. Paid apps that include trial functionality are downloaded 70 times more than paid apps that don't include trial functionality, expanding the number of potential customers to purchase the full paid version.
  • Trials result in higher sales. Nearly 1 out of 10 trial apps downloaded convert to a purchase and
  • generate 10 times more revenue, on average, than paid apps that don't include trial functionality.
  • Trial downloads convert to paid downloads quickly. More than half of trial downloads that convert to a sale do so within one day, and most of those within 2 hours.
                                                                                                                                                                       (Windows Phone 7 Developer Blog)
Microsoft suggests that an application that operates under a trial license be programmed to present the user with a "buy now" option at appropriate times, as determined by the developer. If the user selects the option, the application would use the Show method ofMarketplaceLauncher to transfer control to the application's Windows Phone Marketplace Details page. If the user clicks the Buybutton on that page, Windows Phone Marketplace will present a confirmation page. If the user confirms, the purchase is made and the trial license is replaced with a full license. Control then returns to the application or whatever else is next on the phone's backstack. When and if the application resumes, it must re-query the IsTrial method to detect the change of license and transition to the appropriate behavior for a full license.  (for more information visit the MSDN documentation)
That was all about basic WP7 Trial sample implementation and best practices. Stay tuned with the rest of the content and Part 2 of this series: Creating a Windows Phone 7 Trial Application |Part2: Adding Buy Now Functionality.
Here you can find the full source code:
I hope that the article was helpful.

No comments:

Post a Comment

Related Posts Plugin for WordPress, Blogger...