Unity端
新建个脚本,然后绑定到一个对象上,脚本代码如下,这片代码我就不多说了,不懂得自己
去看下iOS和Unity的互调。弄完后导出IOS工程。
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Runtime.InteropServices;//Must be Defined
public class GetIdentertyControl : MonoBehaviour {
// Use this for initialization
public Text IDFA;
public Text DisplayName;
public Text DeviceModel;
[DllImport("__Internal")]
private static extern void _GetIDFA ();
public void GetIDFA(string str){
if (string.IsNullOrEmpty(str)) {
Debug.Log("IDFA is NULL");
return;
}
IDFA.text = str;
}
[DllImport("__Internal")]
private static extern void _GetDisplayName ();
public void GetDisplayName(string str){
if (string.IsNullOrEmpty(str)) {
Debug.Log("DisplayName is NULL");
return;
}
DisplayName.text = str;
}
[DllImport("__Internal")]
private static extern void _GetDeviceModel ();
public void GetDeviceModel(string str){
if (string.IsNullOrEmpty(str)) {
Debug.Log("DeviceModel is NULL");
return;
}
DeviceModel.text = str;
}
public void OnClickButton(){
if(Application.platform != RuntimePlatform.OSXEditor){
_GetIDFA();
_GetDeviceModel();
_GetDisplayName();
}
}
}