2016-08-01 63 views
0

一切工作正常在Android上,但我不知道如何使它适用于iOS,请帮助。统一共享脚本Android到iOS

using UnityEngine; 
using System.Collections; 
using UnityEngine.UI; 
using System.IO; 
using System; 
using System.Collections.Generic; 

public class ShareMenu : MonoBehaviour 
{ 
    private bool isProcessing = false; 
    public string AppLinkURL { get; set; } 
    private string shareText = "Download This Game"; 
    private string gameLink = "Download the game on play store at " + "\nhttps://play.google.com/store/apps/details?id=com.CrazyDrivers"; 
    public void shareImage() 
    { 
     if (!isProcessing) 
      StartCoroutine(ShareScreenshot()); 
    } 

    private IEnumerator ShareScreenshot() 
    { 
     isProcessing = true; 
     yield return new WaitForEndOfFrame(); 

     string destination = Path.Combine(Application.persistentDataPath, System.DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".png"); 
     Debug.Log(destination); 

     if (!Application.isEditor) 
     { 
      AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent"); 
      AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent"); 
      intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND")); 
      AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri"); 
      intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), shareText + gameLink); 
      intentObject.Call<AndroidJavaObject>("setType", "text/plain"); 
      AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); 
      AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity"); 
      currentActivity.Call("startActivity", intentObject); 

      isProcessing = false; 
     } 
    } 
} 

你能以某种方式帮助我改变了IOS 此代码让我分享到Facebook,Twitter,WhatsApp的。因为在Android上它工作得很好。我是编程的新手。

+0

会发生什么? –

+0

@SP。它只是关闭的应用程序,有时它冻结 –

回答

0

我认为应用程序崩溃是因为您在iOS设备上使用AndroidJavaClass。 你可以试试这个。

#if !UNITY_EDITOR && UNITY_ANDROID 
       AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent"); 
       AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent"); 
       intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_SEND")); 
       AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri"); 
       intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_TEXT"), shareText + gameLink); 
       intentObject.Call<AndroidJavaObject>("setType", "text/plain"); 
       AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer"); 
       AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity"); 
       currentActivity.Call("startActivity", intentObject); 

       isProcessing = false; 
#elif UNITY_IOS 
       //put iOS share code here 
#endif 

如果您的应用程序停止崩溃(但它不会做任何事情。因为我们只允许它在Android设备上运行)。然后,你可以看看iOS的实施。 对于iOS的代码可能会寻找更多的在这里http://forum.unity3d.com/threads/is-it-really-that-hard-to-share-a-simple-score-on-facebook-and-twitter-natively.231390/

为Facebook(只)当您尝试在iOS上部署你应该使用Facebook官方统一SDK https://developers.facebook.com/docs/unity/ https://developers.facebook.com/docs/unity/reference/current/FB.FeedShare

+0

我使用共享束团结,我现在可以分享到Facebook和Twitter等在IO和Android上,但不知道如何改变那里的东西,我想分享游戏链接和得分。但不知道如何 –