崩溃如下: -[CFString release]: message sent to deallocated instance 0x6040005de2d0
代码:
- (void)onResultCallBack:(AndroidIosNativeBase*)target
sign:(NSMethodSignature*)sign
inv:(NSInvocation*)inv {
//获取返回值类型
constchar* returnValueType = sign.methodReturnType;
//声明一个返回值变量
__autoreleasing id returnValue; //此处一定要为__autoreleasing否则会crash
BOOLbVoidReture =NO;
NSString*strReturnValue;
//如果没有返回值,也就是消息声明为void,那么returnValue = nil
if(!strcmp(returnValueType,@encode(void))) {
NSLog(@"没有返回值,即返回值类型为void");
returnValue =nil;
bVoidReture =YES;
}elseif(!strcmp(returnValueType,@encode(id))){
//如果返回值为对象,那么为变量赋值
NSLog(@"返回值类型为对象");
[inv getReturnValue:&returnValue];
strReturnValue = returnValue;
}
}
}else{
//如果返回值为普通类型,如NSInteger, NSUInteger ,BOOL等
NSLog(@"返回类型为普通类型");
//首先获取返回值长度
NSUInteger returnValueLenth = sign.methodReturnLength;
//根据长度申请内存
void* retValue = (void*)malloc(returnValueLenth);
//为retValue赋值
[inv getReturnValue:retValue];
if(!strcmp(returnValueType,@encode(BOOL))) {
returnValue = [NSNumber numberWithBool:*((BOOL*)retValue)];
BOOLbRet = returnValue;
strReturnValue = [NSStringstringWithFormat:@"%@",(bRet ?@"true":@"false")];
}else if(!strcmp(returnValueType,@encode(NSInteger))){
returnValue = [NSNumber numberWithInteger:*((NSInteger*) retValue)];
strReturnValue = [NSStringstringWithFormat:@"%ld",returnValue];
}
}
//函数有返回值
if(!bVoidReture && [targetisKindOfClass:[AndroidIosNativeBaseclass]]) {
AndroidIosNativeBase *native = (AndroidIosNativeBase *)target;
[nativeonResultCallBack:strReturnValue];
}
}