Implementing and debugging trial mode in a WP7 app

Written by Tom Verhoeff on. Posted in WP7

With app numbers in the marketplace already rising over 3K getting your application noticed is more and more important. One of the features a lot of applications still miss is trial mode. Personally i would not consider buying an app unless i get the chance to preview it and i know this opinion is shared by a lot of users around the world.
Fortunately Microsoft provides an easy way of implementing trial mode and a lot of information on different implementations is available all over the web. Since people keep asking me how i implemented it i will cover it in this blogpost.


Trial Mode Basics

The Windows Phone 7 libraries provide easy access to trial information. To determine if an app is running in trial mode you just have to make one function call. The Phone OS will figure out everything for you. It is important to note that this call may take up to 70ms , so make sure you cache the value. I did this by keeping track of the trial status in a public boolean in the App class. Let’s just take a look at a few basic steps to implement this.
1. Add a reference to the marketplace namespace in your App.xaml.cs
using Microsoft.Phone.Marketplace;
2.  Add the required declarations
public Boolean isTrial = false;
private LicenseInformation licenseInfo = new LicenseInformation();
3.  Add function calls to the launched and activated event handlers to refresh trial status on launch.
private void Application_Launching(object sender, LaunchingEventArgs e){
	isTrial = licenseInfo.IsTrial();
}

private void Application_Activated(object sender, ActivatedEventArgs e){
	isTrial = licenseInfo.IsTrial();
}
4.  Check the isTrial status in your code anywhere you want to put limitations
App ap = (App)Application.Current;
if (ap.isTrial)
{
  *trial code*
}
You can also databind ap.isTrial to UI elements

Linking to the marketplace using MarketplaceDetailTask

When confronting a user with trial limitations it is usually a good thing to provide a quick link to the marketplace. This will save some end-user frustration and will also increase your sales. This can be implemented using the MarketplaceDetailTask. Combine it with either a MessageBox or Button for best results:
private void buyNowButton_Click(object sender, RoutedEventArgs e)
{
	MarketplaceDetailTask detailTask = new MarketplaceDetailTask();
	detailTask.Show();
}

MessageBoxResult mbResult = MessageBox.Show("This feature is only
 available in the full version. Go to the marketplace now?", "Limited
  trial", MessageBoxButton.OKCancel);
if (mbResult == MessageBoxResult.OK)
{
	MarketplaceDetailTask detailTask = new MarketplaceDetailTask();
	detailTask.Show();
}
Make sure a button or messagebox only shows when the application is running in trial mode. You can accomplish this by for example collapsing a button and only making it visible of the app is running in trial. Providing links to other applications is also possible by setting the detailTask ContentIdentifier property to your other apps unique id before calling Show().

Debugging

Another problem often encountered is debugging trial mode. When an app has not been retrieved using the marketplace isTrial() will always return false. Using the above code and hardcoding “true” is a way of solving this, but since a like automating everything i came op with this code:
private void Application_Launching(object sender, LaunchingEventArgs e)
{
	if (System.Diagnostics.Debugger.IsAttached)
	{
		if (MessageBox.Show("Test in trial mode?", "Debug Trial",
                 MessageBoxButton.OKCancel) == MessageBoxResult.OK)
		{
			isTrial = true;
		}
		else
		{
			isTrial = false;
		}
	}
	else
	{
		isTrial = licenseInfo.IsTrial();
	}
}
This will check if a debugger is attached and if so display a MessageBox to ask wether or not to run in trial mode.
Update: Like Leon Zandman correctly states using preprocessor directives might be preferred above using the Debugger.isAttached property. Find more information about it here

With this information everyone should be able to implement trial mode in a (Silverlight) Windows Phone 7 app. Please let me know if you encounter any problems or just want to give feedback. Use the comments or the feedback form. Also Follow me on twitter to stay up to date on my WP7 posts

Want to know more about Windows Phone 7 development? Check the App Hub (English) or this MSDN page (Dutch)

Tags: , , , ,

Trackback from your site.

Comments (92)

  • Leon Zandman

    |

    Nice article, however I do have some comments:

    I wouldn’t use the Debugger.IsAttached property check to enable debugging the trial mode. First reason is that this code is evaluated at runtime and will be executed every time. Not only on your device during development, but every time your app is run. So even after users download your app from the MarketPlace, it will still perform that check, which is unnecessary, because in general those users have no debugging business in your app.

    Secondly, if I were able to somehow attach MY debugger to your app (e.g. via jailbreak), I would be able to use your debugging code.

    Lastly, the debugging code will take up valuable space. It might be very minor in this particular case, but sometimes debugging code can be quite larger. If code isn’t used during normal operation, it shouldn’t be included in the first place.

    Personally, I prefer using preprocessor directives to add debugging code to my app. By default Visual Studio defines the DEBUG symbol for DEBUG builds, so using the #if directive you can conditionally add your debugging code and prevent it from being included in RELEASE builds (see: http://msdn.microsoft.com/en-us/library/4y6tbswk.aspx).

    Reply

  • Speaking at DevDays 2011 | Tom Verhoeff

    |

    […] reports & feedback and runtime intelligence during this and next week. I blogged about implementing trial mode back in December, but I will also publish a new and improved post on this […]

    Reply

  • stephen

    |

    For those wanting to use the debug compliler symbol:

    private void Application_Launching(object sender, LaunchingEventArgs e)
    {
    #if DEBUG
    if (MessageBox.Show(“Test in trial mode?”, “Debug Trial”,
    MessageBoxButton.OKCancel) == MessageBoxResult.OK)
    {
    IsInTrialMode = true;
    }
    else
    {
    IsInTrialMode = false;
    }
    #else
    IsInTrialMode = _licenseInfo.IsTrial();
    #endif

    }

    Reply

  • google.com

    |

    I know this website gives quality depending content and additional material, is there any other website which presents these stuff in
    quality?

    Reply

  • Immigration Lawyers Honslow

    |

    First off I would like to say superb blog! I had a quick question in which I’d like to ask if you do not mind. I was interested to find out how you center yourself and clear your head prior to writing. I have had difficulty clearing my mind in getting my ideas out there. I do enjoy writing however it just seems like the first 10 to 15 minutes are lost just trying to figure out how to begin. Any recommendations or tips? Thanks!

    Reply

  • Chun

    |

    It’s really a great and useful piece of info. I am glad that you just shared this useful information with us. Please keep us up to date like this. Thanks for sharing.

    Reply

  • download counter strike: global offensive full version

    |

    This is very attention-grabbing, You are an overly professional blogger.
    I’ve joined your rss feed and look forward to in the hunt for more of your magnificent post. Also, I’ve shared your
    web site in my social networks

    Reply

  • Aimbot download

    |

    Hello! I simply would like to offer you a big thumbs up for your
    excellent info you’ve got here on this post. I’ll be coming back to your site for more soon.

    Reply

  • Leoma

    |

    w zębach
    dratwy. Owczy alom (Leoma) zewłok był spory.

    Musiał taki być, aby pomieścić w sobie fura siarki, saletry,
    węgla drzewnego tudzież ze trzy
    funty hufnali. Wprawdzie przejrzałe klechdy zalecały
    wyłączni.

    Reply

  • HowTo Password Hack Twitter Account

    |

    Magnificent beat ! I would like to apprentice at the same time as you amend your site, how could i subscribe for a blog site?
    The account aided me a appropriate deal. I had been tiny bit acquainted of this your broadcast
    offered bright clear idea

    Reply

  • black tea

    |

    Excellent, what a blog it is! This blog presents
    useful information to us, keep it up.

    Reply

  • george best

    |

    Hi, i think that i noticed you visited my blog thus i got here to return the
    desire?.I am attempting to to find issues to enhance my web site!
    I assume its adequate to make use of some of your ideas!
    !

    Reply

  • program pit

    |

    I create a comment when I especially enjoy a article on a site or I
    have something to add to the discussion. Usually it’s triggered by the fire communicated in the post I looked at. And on this post Implementing and debugging trial mode in a WP7 app | Tom Verhoeff. I was actually moved enough to leave a comment 😛 I actually do have some questions for you if it’s okay.
    Is it only me or do some of these responses come across like written by brain dead folks?
    😛 And, if you are posting on additional online sites, I’d like to follow everything new you have to post. Would you make a list all of your social sites like your twitter feed, Facebook page or linkedin profile?

    Reply

  • rozliczenie pit online

    |

    Hello! Do you know if they make any plugins to assist with Search Engine Optimization?
    I’m trying to get my blog to rank for some targeted keywords but I’m
    not seeing very good success. If you know of any please share.

    Cheers!

    Reply

  • e deklaracje

    |

    After going over a handful of the blog posts on your web
    page, I seriously like your technique of writing a blog.
    I bookmarked it to my bookmark site list and will be checking back in the near future.
    Please check out my web site too and let me know what you think.

    Reply

  • Jeana

    |

    With havin so much content do you ever run into any issues of plagorism or copyright infringement?
    My website has a lot of completely unique content I’ve either written myself or outsourced but it seems a lot of it is popping it up all over the web without my authorization.
    Do you know any solutions to help stop content from being stolen?
    I’d truly appreciate it.

    Reply

  • agbluecom.webstarts.com

    |

    Does your blog have a contact page? I’m having trouble locating
    it but, I’d like to send you an email. I’ve got some ideas for your blog
    you might be interested in hearing. Either way, great website and I look
    forward to seeing it develop over time.

    Reply

  • Corey

    |

    I blog frequently and I really thank you for your information.
    This great article has truly peaked my interest.
    I will book mark your blog and keep checking for new
    details about once per week. I opted in for your Feed as well.

    Reply

  • Clifford

    |

    I am regular reader, how are you everybody? This piece of writing posted at
    this web site is genuinely fastidious. Clifford

    Reply

  • Micah

    |

    Right away I am going to do my breakfast, later than having my breakfast
    coming over again to read additional news.

    Reply

  • http://678cpw.com

    |

    Diе Kernaussage dieser Homepaǥe ist bomƅig, hɑb es am Anfang nicht glauben wollen.

    Reply

  • www.mp3bud.net

    |

    Tolle Informatioոen sind an dieser Stelle ƶu entdecken. Biո ernsthaft erfreut.

    Reply

  • http://imgur.com

    |

    This paragraph will help the internet users for creating new webpage or even a weblog
    from start to end.

    Reply

  • translate google apis

    |

    Ahaa, its pleasant dialogue concerning this post here at this
    blog, I have read all that, so at this time me also commenting at this place.

    Reply

  • casino pa nett

    |

    It’s actually a nice and useful piece of information.
    I’m glad that you just shared this helpful information with us.
    Please stay us up to date like this. Thank you for sharing.

    Reply

  • rent construction dumpsters

    |

    Wow, that’s what I was seeking for, what a data!
    present here at this web site, thanks admin of this site.

    Reply

  • Salvador

    |

    The other day, while I was at work, my sister stole my
    iPad and tested to see if it can survive a thirty foot drop, just so she can be a youtube sensation.

    My apple ipad is now destroyed and she has 83 views. I know this is totally
    off topic but I had to share it with someone!

    Reply

  • tripadvisor reviews ydetector

    |

    Exercise is important when dealing with the effects of HIV.
    Lift your tongue up to the roof of your mouth and
    hold it there for five seconds. Moving to a new home, relocating to a different location or changing jobs all affect the status
    quo. Endomondo Sports Tracker integrates audio feedback at intervals, voice
    messages from friends, workout history and lap times.
    This will help in losing underlying fat and keeps your skin glowing and attractive.

    Reply

  • myVEGAS Slots Free Chips

    |

    Hi, i think that i saw you visited my web site thus i came to “return
    the favor”.I’m trying to find things to enhance my site!I suppose its ok to
    use a few of your ideas!!

    Reply

  • Debora

    |

    It’s very straightforward to find out any topic on
    web as compared to books, as I found this post at this web site.

    Reply

  • Imogene

    |

    Thanks on your marvelous posting! I quite enjoyed reading it, you may be a great author.I will remember to bookmark your
    blog and will often come back later in life. I want to encourage you to
    ultimately continue your great writing, have a nice
    afternoon!

    Reply

  • Triple galop

    |

    Hello to every one, it’s in fact a good for me to go to see this website, it includes helpful Information.

    Reply

  • Brave Frontier Cheats

    |

    If some one desires to be updated with latest technologies
    then he must be pay a quick visit this site and be up to date all the time.

    Reply

  • Johnf642

    |

    I am now not certain the place you’re getting your info, however good topic. I needs to spend some time learning more or figuring out more. Thank you for magnificent info I was on the lookout for this information for my mission. aafeacfeaadk

    Reply

  • www.facebook.com

    |

    Restaurant Mistake #7: Ordering Full Size Portions. It was a good performance, but she may be in trouble of elimination. There will be times when you look over your shoulder, wistful for the days of being his better half.

    Reply

  • pet waste bags cheap

    |

    I am really impressed with your writing talents as smartly as with the format in
    your blog. Is that this a paid subject matter or did
    you modify it your self? Either way keep up the excellent quality writing, it is uncommon to see a nice weblog like this one nowadays..

    Reply

  • Timmy

    |

    Hello just wanted to give you a quick heads up. The text in your post seem to be
    running off the screen in Opera. I’m not sure if this is a format issue or something to do with internet browser
    compatibility but I thought I’d post to let you know.
    The design look great though! Hope you get the problem fixed soon. Many thanks

    Reply

  • Réflexions d'un amateur de vins pdf

    |

    whoah this blog is wonderful i like studying your posts.
    Keep up the good work! You understand, a lot of individuals are looking round for this info, you could help them greatly.

    Reply

  • dont spam

    |

    The gratitude of every home in our Island, in our Empire, and indeed throughout the world, except in the abodes of the guilty, goes out to the British airmen who,
    undaunted by odds, unweaeied in their constant chalenge and mortal danger, are turning the tide of the world war by their prowess and by their devotion. Never in thee field of human conflict was soo much owed by soo many tto
    so few.

    Reply

  • deer antler extract

    |

    Anyone that has ever obtained a gym membership knows the
    type. Any hunter can bag a smaller buck one per year and occasionally get lucky,
    but bringing home that majestic trophy buck with any regularity takes commitment
    and knowledge. The only issue with this is that IGF-1 is on Major League Baseball’s report on banned substances, therefore if theigf-1 spray actually mayenhance IGF-1,
    people could possibly be busted for utilizing theitem.

    Reply

  • Skin Whitening Forever

    |

    Admiring the time and energy you put into your site and in depth information you provide.

    It’s good to come across a blog every once in a while that isn’t
    the same out of date rehashed information. Excellent read!
    I’ve bookmarked your site and I’m adding your RSS
    feeds to my Google account.

    Reply

  • www.facebook.com

    |

    I like what you guys are up too. This type of clever work and exposure!
    Keep up the terrific works guys I’ve you guys to our blogroll.

    Reply

  • good swimming pool

    |

    You have made some decent points there. I looked on the web for additional information about the issue and found most people will go
    along with your views on this web site.

    Reply

Leave a comment