我在函数中使用下面提到的行
NSMutableData *data = [[NSMutableData alloc] init];
我将这个函数称为没有时间(例如 100 次)。所以我的问题是,最初大约 60 次或更多它工作正常,但之后它给了我“BAD_EXC_ACCESS”
功能如下
+ (NSString *) recvToFile:(NSString *)_fileName {
@try {
int _sz = [self recvNumber:4];
uint8_t t[_sz];
NSMutableData *data = [[NSMutableData alloc] init];
NSMutableData *fileData = [[NSMutableData alloc] init];
long _pos = 0;
NSString *_fullPath = _fileName;
while (_sz > _pos) {
long _c = [m_sin read:t maxLength:_sz];
_pos += _c;
data = [NSData dataWithBytes:t length:_c];
if([Misc checkFileExists:_fileName]==nil)
[[NSFileManager defaultManager] createFileAtPath:_fullPath contents:nil attributes:nil];
[fileData appendData:data];
}
[fileData writeToFile:_fullPath atomically:YES];
NSDictionary *attr = [[NSFileManager defaultManager] attributesOfItemAtPath:_fullPath error:nil];
long long length = [[attr valueForKey:@"NSFileSize"] intValue];
if (length >= _sz)
return (_fullPath);
}
@catch (NSException * e) {
}
return (nil);
}
每次收到文件时,我都会调用此函数。我想从字节中保存文件