U3D获取IOS设备所在时区、是否安装指定APP、判断真机还是模拟器

  unity是无法直接获取ios设备信息的,但是unity可以与IOS代码进行交互,这就可以完成你想要实现的功能了。

  直接上代码:

  

CheckCountry.h文件:

#import <Foundation/Foundation.h>
@interface CheckCountry : NSObject
+ (int)_inChina;
+ (int)_isIOSPhone;
+(bool)_IOS_IsInstallApp:(const char*)url;
@end

  

CheckCountry.mm文件:

#import "CheckCountry.h"
@implementation CheckCountry


+ (int)_inChina{
    
     int in_china = 0;
    
    if([[[NSTimeZone localTimeZone] name] rangeOfString:@"Asia/Chongqing"].location == 0 ||
       [[[NSTimeZone localTimeZone] name] rangeOfString:@"Asia/Harbin"].location == 0 ||
       [[[NSTimeZone localTimeZone] name] rangeOfString:@"Asia/Hong_Kong"].location == 0 ||
       [[[NSTimeZone localTimeZone] name] rangeOfString:@"Asia/Macau"].location == 0 ||
       [[[NSTimeZone localTimeZone] name] rangeOfString:@"Asia/Shanghai"].location == 0 ||
       [[[NSTimeZone localTimeZone] name] rangeOfString:@"Asia/Taipei"].location == 0)
    {
        
        in_china = 1;
        
    }
    
    return in_china;
}
+ (int)_isIOSPhone{
    
    int isIOSPhone = 0;
    
    if(TARGET_OS_IPHONE)
    {
        isIOSPhone = 1;
    }
    
    return isIOSPhone;
}
+(bool)_IOS_IsInstallApp:(const char*)url{
    if (url == NULL) {
        return false;
    }
    NSURL *nsUrl = [NSURL URLWithString:[NSString stringWithUTF8String:url]];
    if ([[UIApplication sharedApplication] canOpenURL:nsUrl]) {
        return true;
    }
    return false;
    
}
@end
 
 
extern "C" {
    int _inChina() {
        
        return [CheckCountry _inChina];
      
    }
    int _isIOSPhone() {
        
        return [CheckCountry _isIOSPhone];
        
    }
    
    bool IOS_IsInstallApp(const char *url) {
        
        //        return [CheckApp _IOS_IsInstallApp(url)];
        return [CheckCountry _IOS_IsInstallApp:url];
        
        
    }
}

oc代码主要分为两个文件,一个,h  一个.mm 我也不知道是干嘛的,但是主要代码在.mm中,.h里面的内容好像是供外部使用的。。。我胡说的吧,感兴趣自己查一下~

在@end之前都是oc代码,之后的代码就是要传入unity的方法了。

其中要注意的三点:

1.这两个文件.mm和.h要放到unity的Assets=>Plugins=>IOS路径里面。

2.不能直接传String,要转为char数组传入。

3.oc中布尔值使用的是yes和no,我刚开始担心不能直接传布尔值,用的int 0/1代替,后来发现可以直接传。。。

 

下面上unity代码:

using System.Runtime.InteropServices;
using UnityEngine;

public class CheckRegion : MonoBehaviour {
    [DllImport("__Internal")] 
    private static extern int  _inChina(); 
    public static int inChina() 
    { 
        return _inChina(); 
    } 
    [DllImport("__Internal")] 
    private static extern bool  IOS_IsInstallApp(string ss); 
    public static bool iOS_IsInstallApp(string ss) 
    { 
        return IOS_IsInstallApp(ss); 
    } 
    [DllImport("__Internal")] 
    private static extern int  _isIOSPhone(); 
    public static int isIOSPhone() 
    { 
        return _isIOSPhone(); 
    } 
}

这里的代码,首先要引用命名空间 using System.Runtime.InteropServices;

有了这个命名空间就可以使用 [DllImport(”“)] 标签了。

这个标签就是引用各种插件dll的,然后就可以注册方法了。

 

搞定~

 

转载于:https://www.cnblogs.com/yzxhz/p/9627228.html

要在 Unity3D 应用程序中获得点击方法,可以使用 Frida 进行 hook。以下是一些步骤和示例代码,可用于在 Unity3D 应用程序中获取触摸屏幕的事件和位置。 1. 使用 Frida 连接到 Unity3D 应用程序的进程: ```python import frida # 获取 Unity3D 应用程序的进程 ID unity_process = frida.get_usb_device().get_process("UnityAppName") # 连接到 Unity3D 应用程序的进程 session = frida.attach(unity_process.pid) ``` 2. 枚举 Unity3D 应用程序的所有模块,并寻找包含点击方法的模块: ```python for module in session.enumerate_modules(): if "Assembly-CSharp.dll" in module.name: target_module = module break # 获取点击方法的地址 target_method_address = target_module.find_export_by_name("UnityEngine.Input:Touch").address ``` 3. 使用 Frida hook 点击方法,并将点击事件的位置打印到控制台: ```python def on_message(message, data): if message["type"] == "send": print(message["payload"]) script = session.create_script(""" Interceptor.attach(ptr("%s"), { onEnter: function(args) { var touch = args[0]; var position = touch.add(4).readPointer().readFloat() + "," + touch.add(8).readPointer().readFloat(); send(position); }, onLeave: function(retval) { } }); """ % target_method_address) script.on("message", on_message) script.load() ``` 该脚本会在点击事件发生时被调用,并将事件的位置打印到控制台。 请注意,以上示例仅仅是一个简单的示例,具体实现可能取决于您正在分析的应用程序的具体情况。您需要根据您的需要修改示例脚本,并确保您的行为符合法律要求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值