我正在使用以下代码从任何 ftp 服务器加载列表:
self.networkStream = CFBridgingRelease(
CFReadStreamCreateWithFTPURL(NULL, (__bridge CFURLRef) url)
);
assert(self.networkStream != nil);
//[self.networkStream setProperty:@"ANONYMOUS" forKey:(id)kCFStreamPropertyFTPUserName];
//[self.networkStream setProperty:@"abc" forKey:(id)kCFStreamPropertyFTPPassword];
self.networkStream.delegate = self;
[self.networkStream scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
[self.networkStream open];
它完美地加载了列表。然后我在 UITableView 中显示列表。加载数据后,我将使用以下代码关闭流:
if (self.networkStream != nil) {
[self.networkStream removeFromRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
self.networkStream.delegate = nil;
[self.networkStream close];
self.networkStream = nil;
}
当用户点击任何单元格时,我试图加载该文件夹的列表(如果它是一个文件夹),否则我必须从 ftp 服务器下载文件。为此,我通过更改 url 使用此代码:
self.networkStream = CFBridgingRelease(
CFReadStreamCreateWithFTPURL(NULL, (__bridge CFURLRef) url)
);
/* [self.networkStream setProperty:( id) kCFBooleanFalse
forKey:( NSString *) kCFStreamPropertyFTPAttemptPersistentConnection
];
*/
assert(self.networkStream != nil);
//[self.networkStream setProperty:@"ANONYMOUS" forKey:(id)kCFStreamPropertyFTPUserName];
//[self.networkStream setProperty:@"abc" forKey:(id)kCFStreamPropertyFTPPassword];
self.networkStream.delegate = self;
[self.networkStream scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSDefaultRunLoopMode];
[self.networkStream open];
但是它在这条线上崩溃了:
CFReadStreamCreateWithFTPURL(NULL, (__bridge CFURLRef) url)
在这一行给出EXC_BAD_ACCESS。我无法弄清楚原因。请帮帮我。