更改网址时CFReadStreamCreateWithFTPURL()崩溃

时间:2013-06-07 10:47:53

标签: ios cfstream

我使用以下代码从任何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服务器下载该文件。为此,我通过更改网址来使用此代码:

          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 。我无法弄清楚原因。请帮帮我。

0 个答案:

没有答案