While building my apps for WP7 that users will pay for, I like to create a trial so the users can try out my app before they buy it. But when you are debugging your app there is no Trial simulation. So Looking on the web I found one.
Here is what i do to simulate trial mode in my Windows Phone 7 apps.
First at the top of your App.xaml.cs file add this
*EDIT*
I forgot to put this in here at the top. You need it to access the licence information.
|
1 2 |
//Used to determine if app is running under a trail license. private static LicenseInformation _licenseInfo = new LicenseInformation(); |
and to use that you will need to add in the folling using statment.
|
1 |
using Microsoft.Phone.Marketplace; |
*END EDIT*
|
1 2 3 4 5 6 7 8 |
private static bool _isTrial = true; public bool IsTrial { get { return _isTrial; } } |
I usually add that in right under my RootFrame property.
I then create a method in my App.xaml.cs
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
private void CheckLicense() { #if DEBUG if (MessageBox.Show("This is for debugging purposes. This allows trial mode to be set. Press 'OK' to simulate trial mode. Press 'Cancel' to run the application in normal mode.", "Debug Trial", MessageBoxButton.OKCancel) == MessageBoxResult.OK) { _isTrial = true; } else { _isTrial = false; } #else _isTrial = _licenseInfo.IsTrial(); #endif } |
I then put the CheckLicence method into my Application_Launching and Application_Activated methods in my App.xaml.cs file to check if the application is bought or a trial version.
Then in your code you set up what will happen in your trial version and all you have to is check the IsTrial if true, it is a trail version. If false it is a full/paid version.
|
1 2 3 4 |
if ((Application.Current as App).IsTrial) { //Do trial things in here } |
I hope this helps you out creating your WP7 app!
(EDIT: Putting this code in will check if trial or not after you buy the app, check out my post here http://www.underbridgecity.net/blog/2012/04/update-to-my-trial-mode-post/)
Much easier way of doing this.
1. Install-Package SlickThoughtTrialManager via nuget command line (or through the GUI)
2. Add info on this page to your App.xaml (http://www.slickthought.net/post/2010/08/30/Managing-Trial-Applications-for-Windows-Phone-7.aspx)
I like how the SlickThoughtTrialManager offers the timed and limited usage option. I will look into that option.
What I like about my version is when I am running in debug mode, it asks if I want to run in trial mode or not. I haven’t seen if SlickThought does that or not yet.
Thank you for this information, I will check it out and might look into using it.
What I *really* dislike about trial apps that (only) check in App.xaml.cs is the fact that if you use the in app option to go to marketplace to buy it (most of them have this, in About page or something), buy it and use back button to go back to it, you return to a trial version of the app you already just bought. This pisses me off when it happens. I need to go back one more (to close the app) and start it again to get the non-trial version. So please, whatever you do (hand rolled, SlickThrought or other trial manager), please *also* check the IsTrial licence information (updating the same flag in your App class) in the OnNavigatedTo handler of the page where you offer the “Buy Me Now” option (like the About page) so the app actually checks if it has been bought in the meantime if people used that option. Should be a best practice somewhere, I think…
peSHIr, I am currently not 100% sure on this, but I beleive my solution does handle that. Becasue I have the CheckLicense method in my Application_Launching and Application_Activated methods, when ever the application is opened either by clicking on the icon or clicking back. the CheckLicence code is run, and when it runs it should get the license information as being bought and all _isTrail checks will return false instead of true.
I will test this out when I get the app I am currently working on into the marketplace, and make another blog post on it.
Also not 100% sure, but I suspect that since Mango brought fast app resume (where app data could just stay in memory instead of true tombstoning, hence not firing any Application events, but just the navigation events of pages) there might be problems with this.
I do know I’ve seen way to many apps that show the behavior: Trial app, go buy it through link/button in app somewhere (like About screen), return to app and it’s still Trial, and only after multiple Back buttons presses and restarting the app is it no longer in Trial mode.
I’m afraid my one and only non-free app so far (which will need an update before Juli anyway..) has this same behavior, by the way..
When I am testing my app using this method. Every time I start up the app (click the tile, hitting the back button, press and hold back button to get the list of apps and then select my app) I always have the CheckLicense method called.
So for right now I am going to assume that every time the application is started or activated, even with fast application switching, the CheckLicence method is called since I have it set up in my Application_Launching and Application_Activated methods. So in theory, after a user buys this app and clicks the back button the CheckLicense method will be called and should determine it is now the full app instead of a trail.
I am hoping to submit my app to the marketplace in a few days, and once it is out there I will test this out to see if it works.
Have you checked that last scenario explicitly?
1) open app
2) check that is in Trial mode
3) buy the app *)
4) use back button to return to page you were on before buying the app
5) check that app is now in normal (non-trial) mode.
*) Either using the “Buy me now” option in your app (which should go directy to app page where you can use the Buy button) or by using Windows button, selecting Marketplace app (either from app list or because you pinned it to home), find your app and hit the Buy button that way.
Since the app I am currently working on is just me debugging it, I can’t actually buy the app. But as soon as it get into the marketplace I will test buying the app and seeing if it works.
The way I tested it is, I open up the app. I get asked if I want to start the app in trial mode or not. I select trial. I then hit the buy my app button. It takes me to the marketplace, but since it isn’t in the marketplace, the marketplace returns an error and I am then sent back into the app. I then get asked again if I want to start the app in trial mode or not.
I also tested leaving the app and then hitting back button to go back into it and pressing the back button and selecting it. Every time I get asked if I want to open the app in trial or not.
When my app asks if it should be in trial mode or not is the CheckLicense method. Which in debug mode asks you so you can test it either way, and in release mode will get the licence information. So I am thinking that every time the app starts it will check the licence information. The only thing I currently do not know is if the licence information gets cashed in any way so that if you click back it will get the licence information from before you bought it or not. That is what I am going to test when my app gets into the marketplace, and I will report back with my findings.
Did you actually get round to explicitly checking the scenario I outlined on the published app…?
I will be doing that today or tomorrow. I plan on recording it to show everyone if it works or not.