崩潰如下: -[CFString release]: message sent to deallocated instance 0x6040005de2d0
代碼:
- (void)onResultCallBack:(AndroidIosNativeBase*)target
? ? ? ? ? ? ? ? ? ? sign:(NSMethodSignature*)sign
?? ? ? ? ? ? ? ? ? ? inv:(NSInvocation*)inv {
? ? //獲取返回值類型
? ? constchar* returnValueType = sign.methodReturnType;
? ? //聲明一個(gè)返回值變量
?? __autoreleasing? id returnValue; //此處一定要為__autoreleasing否則會(huì)crash
? ? BOOLbVoidReture =NO;
? ? NSString*strReturnValue;
? ? //如果沒有返回值,也就是消息聲明為void,那么returnValue = nil
? ? if(!strcmp(returnValueType,@encode(void))) {
? ? ? ? NSLog(@"沒有返回值,即返回值類型為void");
? ? ? ? returnValue =nil;
? ? ? ? bVoidReture =YES;
? ? }elseif(!strcmp(returnValueType,@encode(id))){
? ? ? ? //如果返回值為對(duì)象,那么為變量賦值
? ? ? ? NSLog(@"返回值類型為對(duì)象");
? ? ? ? [inv getReturnValue:&returnValue];
? ? ? ? ?strReturnValue = returnValue;
? ? ? ? ? ? }
? ? ? ? }
? ? }else{
? ? ? ? //如果返回值為普通類型,如NSInteger, NSUInteger ,BOOL等
? ? ? ? NSLog(@"返回類型為普通類型");
? ? ? ? //首先獲取返回值長度
? ? ? ? NSUInteger returnValueLenth = sign.methodReturnLength;
? ? ? ? //根據(jù)長度申請(qǐng)內(nèi)存
? ? ? ? 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];
? ? ? ? }
? ? }
? ? //函數(shù)有返回值
? ? if(!bVoidReture && [targetisKindOfClass:[AndroidIosNativeBaseclass]]) {
? ? ? ? AndroidIosNativeBase *native = (AndroidIosNativeBase *)target;
? ? ? ? [nativeonResultCallBack:strReturnValue];
? ? }
}