Issue related with Unity

ios
android
api

#1

Hi everyone! I am new here and very glad to meet u. I am an Unity Coder and have a problem with sharing image from unity game to twitter. I will be highly grateful if somebody could give some advice about this issue.

This is my main code:

namespace Fabric.Internal.Twitter
{
using UnityEngine;
using Fabric.Twitter;
using System.IO;
using System.Collections;

public class TwitterInit : MonoBehaviour
{
	private static TwitterInit instance;


	void Update () {

		ShareCard ();

	}


	void Awake()
	{
		// This singleton pattern ensures AwakeOnce() is only called once even when the scene
		// is reloaded (loading scenes destroy previous objects and wake up new ones)
		if (instance == null) {
			AwakeOnce ();

			instance = this;
			DontDestroyOnLoad(this);
		} else if (instance != this) {
			Destroy(this.gameObject);
		}
	}

	private void AwakeOnce ()
	{
		Twitter.Init();

	}

//the method ShareCard scans the var JSCsharpCommunicator.whichPlatform. an assignment of value 3 indicates that its time to make screenshot and send it to twitter.

	public void ShareCard () {

		if (JSCsharpCommunicator.whichPlatform == 3) {

			if (QR_Code.timetoEncode == 3) {

				StartCoroutine(TakeScreenshot ());


				QR_Code.timetoEncode = 4;
			}
			else if(QR_Code.timetoEncode == 2){

				startLogin ();

			}



		}



	}



	public void startLogin () {

		TwitterSession session = Twitter.Session;

		if (session == null) {
			Twitter.LogIn (LoginComplete, LoginFailure);
		} else {
			LoginComplete (session);
		}

	}



	public void LoginComplete (TwitterSession session) {
		// Start composer or request email

		startComposer (session, Application.dataPath+"/Resources/"+"shared"+".png");

		ShowMessage (6);
		JSCsharpCommunicator.StarAmountMod = 
                    JSCsharpCommunicator.StarAmountModValueForShare;

	}



	public void LoginFailure (ApiError error) {

		ShowMessage(7);


	}







	public void startComposer(TwitterSession session, string imageUri) {

		Card card = new AppCardBuilder()
			.ImageUri (imageUri)
			.GooglePlayId ("com.xxxx.xxxx.app.android")
			.IPhoneId ("123456789")
			.IPadId ("123456789");

		Twitter.Compose (session, card);
	}

//take screen shot

	private IEnumerator TakeScreenshot() 
	{
		yield return new WaitForEndOfFrame();

		var width = Screen.width;
		var height = Screen.height;
		var tex = new Texture2D(width, height, TextureFormat.RGB24, false);
		// Read screen contents into the texture
		tex.ReadPixels(new Rect(0, 0, width, height), 0, 0);
		tex.Apply();

		byte[] screenshot = RotateScreenshot(tex).EncodeToPNG();

		File.WriteAllBytes(Application.dataPath+"/Resources/"+"shared"+".png",screenshot);

		QR_Code.timetoEncode = 2;
	}

//rotate screenshot from portrait to landscape to meet twitter card requirements.

	private Texture2D RotateScreenshot(Texture2D Origin)
	{
		var width = Screen.width;
		var height = Screen.height;
		var Landscape = new Texture2D(height, width, TextureFormat.RGB24, false);


		for(var a=0;a<width;a++){

			for(var b=0;b<height;b++){

				Landscape.SetPixel(b, width-a, (Origin.GetPixel (a, b)));

			}

		}

		return (Landscape);

	}

//give feedback to UI Interface so that user see notification informing about if sharing is finished or failed.

	private void ShowMessage(int whichCase)
           {

		JSCsharpCommunicator.whichPlatform = 0;
		QR_Code.timetoEncode = 0;
		JSCsharpCommunicator.TimetoResume = whichCase;


	}


}

}

the above shown code is attached to an empty Gameobject named “twitterInit”(the default one everyboy will have if fabric twitter kit is integrated into unity) .

My issue is, on my mac in the unity project remote device interface(not real mobile device). everything works fine and I got this notification in the console:

[Twitter] Would call Twitter Compose on a physical device for user Editor with Image URI /Users/hanyi/Desktop/GiveMeFiveFinal/Assets/Resources/shared.png

But on the mobile device(so far tested on android), it does not work. The method “ShowMessage” is never called which means my device did never get any info about LoginComplete or LoginFailure. I cant get issue solved on my own.

Thank you so much for any help in advance!!