How to open Appstore in Unity? (iOS and Android)

How to open Appstore in Unity for iOS and Android? And how to not leave app when doing it?

You can just download my NativeAppstore.unitypackage, and import it into your project. (I haven’t wrote about the nitty gritty of creating Unity plugins yet, so this post will not go into the iOS or Android codes)

You can take a look at AppstoreTestScene.cs:

using UnityEngine;
using System.Collections;

public class AppstoreTestScene : MonoBehaviour 
{
    public string m_appID_IOS = 840066184;
    public string m_appID_Android = com.orangenose.noone;

    public void OnButtonClick(string buttonName)
    {    
        if(buttonName == ViewApp)
        {    
            if(!Application.isEditor)
            {
                #if UNITY_IPHONE
                AppstoreHandler.Instance.openAppInStore(m_appID_IOS);
                #endif

                #if UNITY_ANDROID
                AppstoreHandler.Instance.openAppInStore(m_appID_Android);
                #endif
            } else
            {    Debug.Log(AppstoreTestScene:: Cannot view app in Editor.);
            }
        }
    }
}

Pass your iOS and Android ID to AppstoreHandler (which is a Singleton), and it will be in charge of opening your Appstore for you.

For iOS, I use SKStoreProductViewController when its available, and if it’s not it defaults back to OpenURL (that unfortunately will pop you out of your app).

For Android, I use Uri Intent.

They are modal views, which means that it will not pop you out of your app. For iOS, just click Cancel, while for Android, just click Back Button to go back to your Unity scene.

IMG_7666 Screenshot_2014-12-02-22-10-30

When can you use this? For example, you want your players to rate your app, or you want to cross sell another of your apps.

All the codes are available on Github: https://github.com/purplelilgirl/Unity-NativeAppstore

By the way, the Apps shown in the tutorial is Toughest Game Ever 2, which is available for iOS and Android, and I’m part of the team that made the game. So please check it out, download, show us some love?

 

Advertisements

3 thoughts on “How to open Appstore in Unity? (iOS and Android)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s