场景:unity游戏接入第三方sdk时,经常伴随着数据传递,参数类型一般有 int string byte[] 前两张很简单 但是byte[] 传递起来就费劲了 我们下面重点用java和oc 来实现这个传递过程。
1、c# 与oc交互
//unity 传参给ios c# 转 c
public override void Init(int appid, string groupid,byte[] data){
__Init(appid, groupid,data,data.count)
}
[DllImport("__Internal")]
private static extern void __Init(int appid, string groupid,byte[] data,int Length);
//ios 接收参数 NativeCodeGlobalInterface.m
#import "NativeCodeGlobalInterface.h"
@implementation NativeCodeGlobalInterface
//类方法写在这里面
@end
#if defined(__cplusplus)
extern "C"{
#endif
void __Init(int appid, const char* groupid,UInt8 *msgByteArrayData, int ArrayLength,)
{
//byte[] 到c 这边对应的类型是 uint8 * 然后转成oc NSData类型方便我们使用
NSData *data = [[NSData alloc] initWithBytes:msgByteArrayData length:ArrayLength];
//TODO OC 拿到数据之后自己处理
}
#if defined(__cplusplus)
}
#endif
2、c#与java交互 比较简单这里简