Issue related with Unity



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;
		} else if (instance != this) {

	private void AwakeOnce ()


//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 = 


	public void LoginFailure (ApiError error) {



	public void startComposer(TwitterSession session, string imageUri) {

		Card card = new AppCardBuilder()
			.ImageUri (imageUri)
			.GooglePlayId ("")
			.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);

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


		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!!