Tip: Rate My App – AIR style

Working on a mobile game or app with AIR mobile, one of the common tasks is putting a rate alert box – some sort of rating request that prompts the user to leave a review on the App store. This can be something like this:

One way to achieve that would be with a native extension (ANE).  There are also plenty of examples of how to code it in native Android or iOS, but with AIR we want to address all platform with the same code, if possible.

I will show an easy way to do just that  in your AIR mobile app with just plain old AS3, and handle both Apple and Google app stores.

The first part is showing the prompt. Just use your favourite UI component or your own popup skin to create and show a popup with two buttons. You are not restricted to UIKit style or Android style – I always like to customize it the same style of the game/app.

Next, we need to get the App id for the app store. In the case of iOS, this would be the ‘AppStore ID’ provided when you submit your app – a numerical ID. To find it, log into iTunesConnect and go to ‘Manage Your Applications’ and select your app. This will show a page like this:

In the details page above, the Apple ID value (numerical) is the ID required.

For Android we use Google Play store ID. This is more straight forward –  just use the app ‘id’ declared in your AIR app.xml (in the id tag). However, the ADT adds an ‘air’ prefix to the id, so this would be something like ‘air.com.mydomain.myapp’.

On the click handler for the ‘rate’ button place a call:

    // handle 'rate'
    openRatePage();

The app store page is accessible from the app simply by navigating to the right URL. When run on the device, this will open the App Store (or Play store) right on the app page, so the user can place a review.

	// App ID - Replace with your app id
	private static const APPLE_APP_ID:String= "123456789";
	private static const PLAY_APP_ID:String= "air.com.domain.mygame"; 
 
	// Store URIs
	private static const PLAY_STORE_BASE_URI:String= "market://details?id=";
	private static const PLAY_REVIEW:String= "&reviewId=0";
	private static const APP_STORE_BASE_URI:String= "http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewContentsUserReviews?onlyLatestVersion=false&type=Purple+Software&id=";
 
	// Open the review page in the app store
	//
	public function openRatePage():void
	{
	    var appUrl:String = APP_STORE_BASE_URI + APPLE_APP_ID;
	    if (isAndroid()) {
		appUrl = PLAY_STORE_BASE_URI + PLAY_APP_ID + PLAY_REVIEW;
	    }
 
	    // Open store URI 	
	    var req:URLRequest = new URLRequest(appUrl);
	    navigateToURL(req);
	}
 
	public function isAndroid():Boolean
	{
	    return Capabilities.manufacturer.indexOf('Android') > -1;
	}

That is all.
Note that the code will not work when running on desktop (simulator), so you will need to create a build and install it on a device to actually test it.

Another common problem is that the app is not yet in the store, or not yet submitted, so the app page will not be found. The simple way around it is to borrow an ID from another app  that’s already in the store and use it for testing. For example, Temple Run (Apple ID: 420009108, Google ID: com.imangi.templerun).
Once everything is working, place back your app ID before making the final build.

, , ,

6 Responses to Tip: Rate My App – AIR style

  1. flash-bob December 7, 2012 at 11:12 pm #

    Hi, this one i very helpful. But can you explain what “PLAY_REVIEW” does?

  2. Flexwiz December 8, 2012 at 9:46 am #

    @flash-bob,
    this is just a parameter added to the store URL so that the page will open on the review tab.

  3. wovenaironathan Hart December 8, 2012 at 5:04 pm #

    Nice tip, but just keep in mind asking users to rate you “5 stars” will get your app rejected for trying to influence the user :)

  4. Pierre April 19, 2013 at 6:57 am #

    Hello Flexwiz,

    Do you know aswell how to get the newest comment directly.
    &reviewId=0 open on the review tab
    but it seems that &reviewSortOrder=0 1 or 2 doesnt allow me to have directly the newest comment

    Would you have any idea how to do this ?

    Thanks in advance

  5. jonsi May 22, 2013 at 5:48 pm #

    Great post … very helpful

Trackbacks/Pingbacks

  1. Tip: Rate My App – AIR style | TechnoVeille - January 16, 2013

    [...] Article original : ici [...]