美文网首页
Unity和IOS交互char*作为方法返回值到C#中bug

Unity和IOS交互char*作为方法返回值到C#中bug

作者: codingriver | 来源:发表于2017-12-06 20:08 被阅读4次

修复方法
id不能直接返回,必须分配内存


#import "IosTools.h"

#if defined (__cplusplus)
extern "C" {
#endif
    //char*分配内存
    char* StringCopy (const char* string)
    {
        
        if (string == NULL)
            return NULL;
        
        char* res = (char*)malloc(strlen(string) + 1);
        
        strcpy(res, string);
        
        return res;
        
    }
//获取imei,id不能直接返回,必须分配内存
char* GetImei ()
{
    NSLog(@"GetImei");
    NSString *uuid = [[[UIDevice currentDevice] identifierForVendor] UUIDString];
    char* id=[uuid UTF8String];
    NSLog(@"GetImei1111");
    return StringCopy(id);
}

#if defined (__cplusplus)
}
#endif

相关文章

网友评论

      本文标题:Unity和IOS交互char*作为方法返回值到C#中bug

      本文链接:https://www.haomeiwen.com/subject/ejwlixtx.html