SampleFTPSample代码中的iOS 6 EXC_BAD_ACCESS

时间:2012-09-25 07:23:54

标签: ftp-client ios6

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

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

非常感谢。

EXC_BAD_ACCESS Fig.1 EXC_BAD_ACCESS Fig.2 EXC_BAD_ACCESS Fig.3

3 个答案:

答案 0 :(得分:8)

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

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

答案 1 :(得分:1)

yeahh !!我终于得到了解决方案。在主线程完成后我调用了uialertview show。所以它现在不会崩溃。在我的情况下。所以没有确切的答案,但你也可以申请 peterlawn。也许对你来说也是有用的。 !!

答案 2 :(得分: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];
}

}