3

我运行从 iOS 开发者中心下载的 SampleFTPSample 源代码(iOS6.0 SDK,Xcode4.5)。 SampleFTPSample

作为图像,当我从 ftpServer 检索列表时,有时会出现 EXC_BAD_ACCESS 错误。我没有修改代码,我不知道为什么,我该如何修复它?

非常感谢。

EXC_BAD_ACCESS 图1 EXC_BAD_ACCESS 图2 EXC_BAD_ACCESS 图 3

4

3 回答 3

8

通过在创建流后立即将 kCFStreamPropertyFTPAttemptPersistentConnection 属性设置为 false(使用 CFReadStreamCreateWithFTPURL)来执行此操作。这可能是这样的:

 success = [self.networkStream setProperty:(__bridge id) kCFBooleanFalse
    forKey:(__bridge NSString *) kCFStreamPropertyFTPAttemptPersistentConnection
];
assert(success);
于 2012-10-16T02:28:55.433 回答
1

是啊!!我终于得到了解决方案。我在主线程完成后调用了 uialertview show。所以它现在不会崩溃。这是我的情况。所以没有确切的答案,但你也可以应用这个 peterlawn。可能对您也有用。!!

于 2012-10-09T07:04:34.837 回答
0
- (void)_startReceive:(NSString*) urlPath
{
BOOL                success;
NSURL *             url;
CFReadStreamRef     ftpStream;

assert(self.networkStream == nil);      // don't tap receive twice in a row!

// First get and check the URL.

if(urlPath != nil)
{
   ...url = FTP_URL here... 
}
success = (url != nil);
// If the URL is bogus, let the user know.  Otherwise kick off the connection.
if ( ! success) 
{
    [self _updateStatus:@"Invalid URL"];
} 
else 
{

    // Create the mutable data into which we will receive the listing.

    self.listData = [NSMutableData data];
    assert(self.listData != nil);

    // Open a CFFTPStream for the URL.

    ftpStream = CFReadStreamCreateWithFTPURL(NULL, (__bridge CFURLRef) url);
    assert(ftpStream != NULL);

    self.networkStream = (__bridge NSInputStream *) ftpStream;



    success = [self.networkStream setProperty:(__bridge id) kCFBooleanFalse
    forKey:(__bridge NSString *) kCFStreamPropertyFTPAttemptPersistentConnection
               ];
    assert(success);


    self.networkStream.delegate = self;
    [self.networkStream scheduleInRunLoop:[NSRunLoop currentRunLoop]forMode:NSDefaultRunLoopMode];
    [self.networkStream open];

    // Have to release ftpStream to balance out the create.  self.networkStream 
    // has retained this for our persistent use.

    CFRelease(ftpStream);

    // Tell the UI we're receiving.

    [self _receiveDidStart];
}

}

于 2012-11-07T11:17:22.477 回答