0
以下是我上傳日誌文件到FTP的代碼,並且問題有時會在執行[mInputStream打開]時崩潰。 XCode顯示我BAD_ACCESS。我想這可能是上傳一個大尺寸文件的結果。但是,有時會發生BADACCESS,即使文件大小也很小。所以我猜尺寸不是主要原因。任何人都可以幫忙太感謝了。NSInputStream打開BAD_ACCESS
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
BOOL success;
NSURL *url;
CFWriteStreamRef ftpStream;
mFinish = NO;
mUploadPath = [[NSString alloc] initWithFormat:@"%@/%@",[UtilityHelper logFolderPath], [mPathList objectAtIndex:0]];
//NSLog(@"mUpLoadPath:%d",[mUploadPath retainCount]);
[mPathList removeObjectAtIndex:0];
// check url
url = [UtilityHelper smartURLForString:FTP_URL];
url = [NSURL URLWithString:[NSString stringWithFormat:@"%@%@", url.absoluteString, [[UIDevice currentDevice] uniqueIdentifier]]];
success = (url != nil);
if (success) {
url = [NSMakeCollectable(CFURLCreateCopyAppendingPathComponent(NULL, (CFURLRef) url, (CFStringRef) [mUploadPath lastPathComponent], false)) autorelease];
success = (url != nil);
}else
return;
mInputStream = [[NSInputStream inputStreamWithFileAtPath:mUploadPath] retain];
[mInputStream open];
// Create CFFTPStream for the URL
ftpStream = CFWriteStreamCreateWithFTPURL(NULL, (CFURLRef) url);
assert(ftpStream != NULL);
mNetworkStream = [(NSOutputStream*)ftpStream retain];
NSLog(@"<<<<<<**>retain count:%d", [mNetworkStream retainCount]);
success = [mNetworkStream setProperty:FTP_USERNAME forKey:(id)kCFStreamPropertyFTPUserName];
assert(success);
success = [mNetworkStream setProperty:FTP_PWD forKey:(id)kCFStreamPropertyFTPPassword];
assert(success);
//[mNetworkStream self
mNetworkStream.delegate = self;
[mNetworkStream scheduleInRunLoop:[NSRunLoop currentRunLoop] forMode:NSDefaultRunLoopMode];
[mNetworkStream open];
CFRelease(ftpStream);
[pool release];