U3D获取ios信息:IDFA、设备型号、包名

这篇博客介绍了如何在Unity游戏中获取iOS设备的IDFA、设备型号和应用显示名称。通过创建OC类并利用UnitySendMessage进行消息传递,实现Unity与iOS原生代码的交互。涉及到的iOS库包括AdSupport.framework和Security.framework。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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();
        }
    }
}



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值