Initial setup

Adding permissions

Batch Unity is compatible with Unity 5.2+ and with both iOS 6+ (with Xcode 6+) and Android 2.3+.

Other platforms supported by Unity (such as the Web Player or Standalone executables) are not supported by Batch. This also applies to testing your game in the Unity Editor itself even if you are building for Android or iOS.

Batch only requires one permission: Internet access, so you need to be sure you have it in your android manifest (in the AndroidManifest.xml xml available into the Assets/Plugin/android-v1 directory of your project) otherwise Batch will not start correctly on Android.

<uses-permission android:name="android.permission.INTERNET" />

Setting up the SDK

The only thing you need to do is to download Batch Unity package and import it using the Assets menu.

Android specific setup

If you haven't done so recently, please update your Android SDK to the latest version of the build-tools, platform-tools and SDK platform. Make sure that your Unity Activity class (specified in the Assets/Plugins/android-v1/android-v1Manifest.xml) is com.batch.android.unity.BatchPlayerActivity.

The manifest activity line should look like this :

<activity android:name="com.batch.android.unity.BatchPlayerActivity" [...]

A sample manifest is included, look for Assets/Plugins/android-v1/android-v1Manifest_Batch_Sample.xml.

Batch Unity will automatically bind itself on the app lifecycle events. You do not need to implement anything yourself.

RECOMMENDED


- If you are using Prime31, you can integrate Batch without replacing the Activity.
- If you are having any technical issues during the integration, you might want to take a look at our troubleshooting section.

Your first start

The preferred way to include Batch in your scene is to create a GameObject and add the Batch/BatchPlugin.cs Mono script as a component. You will then be able to reference this Batch instance from your other scripts by binding it in the inspector.

The start function requires you to provide a configuration object, so a typical implementation will be:

using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using Batch;

public class MainMenu : MonoBehaviour
{

	public BatchPlugin BatchPlugin;
	
	void Start()
	{
		Config config = new Config();
		config.IOSAPIKey = "YOUR_IOS_APIKEY";
		config.AndroidAPIKey = "YOUR_ANDROID_APIKEY";
		BatchPlugin.StartPlugin(config);
	}
}

YOUR_API_KEY is your Batch Dev or Live API key. You'll find the API keys needed to set up the SDK in Batch's settings (⚙️ Settings → General):

  • Dev API key: Use it for development or testing purposes. This API key won't trigger stats computation. Please take care not to ship an app on a Store with this API key.
  • Live API key: Should be used in a production environment only and in the final version of your app on the Store.

Please note that you should not use the same API key for iOS and Android. If you do not want to support one of these platforms, you are not required to provide an API Key for it.

The iOS API key must not be mistaken for the APNS environment Batch will output to the Xcode logs when starting. The environment depends on the app's provision, not on the Batch API key used.

Testing your integration

Congratulations on finishing the bulk of the integration!

If you want to validate your implementation before proceeding with the Push setup, you can locate the log that Batch posts in your app log in devmode.

  • On Android, you can access the logcat through your preferred method, although using Android Studio's method is quite simple.
  • On iOS, you will find it in the Xcode console after deploying a build to your device while linked to your Mac.

Here is how it should look after a correct integration:

Batch: Batch is running in dev mode (your API key is a dev one)
[Batch] Batch started with a DEV API key