Using Parse SDK with Unity – running on an Android Device

unityandroid

If you are using Parse for your back-end server in a Unity app, and you want to deploy the app to Android, you may run into some issues with the built-in Parse plugin. Specifically (at least in my case with Unity 4.6 and Android KitKat) the Parse query object doesn’t ever return a result.

As a work-around I ended up going with a solution using Unity’s WWW class and the Parse REST API.

 

 

 


private IEnumerator GetParseDataForAndroid () {

	//new WWW object
	WWWForm form = new WWWForm();


	//set headers, not sure why but I had to set twice to get it to work
	Hashtable headers = form.headers.AddAuthorizationHeader("Your-Parse-Application-Id", "javascript-key=Your-Parse-REST-API-Key");

	headers.Add("X-Parse-Application-Id","Your-Parse-Application-Id");
	headers.Add("X-Parse-REST-API-Keyd","Your-Parse-REST-API-Key");

	WWW parseRequest = new WWW("https://Your-Parse-Application-Id:javascript-key=Your-Parse-REST-API-Key@api.parse.com/1/classes/yourObject", null, headers);


		//yield until request is done
		yield return parseRequest;


		//request is done, process results
		Debug.Log (" MergeVRBridge parse query eror result is " + parseRequest.error);


		//using simplejson
		var V = JSON.Parse (parseRequest.text);

		JSONArray results = V ["results"].AsArray;

		for (int i=0; i<results.Count; i++) {

			JSONClass jObject = results[i].AsObject;
			
			//do something interesting with results
			string sTitle = jObject["title"];
			Debug.Log(" yourObject " + sTitle);

			
			
		}




}