【问题标题】:iOS 6 EXC_BAD_ACCESS in SampleFTPSample codeSampleFTPSample 代码中的 iOS 6 EXC_BAD_ACCESS
【发布时间】:2012-09-16 16:23:15
【问题描述】:

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

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

非常感谢。

【问题讨论】:

  • 得到这个问题的任何解决方案?

标签: ftp-client ios6


【解决方案1】:

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

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

【讨论】:

  • 你能解释一下这是做什么的以及为什么它是必要的吗?这是 ios6 的新功能吗
【解决方案2】:

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

【讨论】:

  • 有没有更好的方法来解决这个问题,因为我需要在用户使用应用程序时在后台进行 FTP 连接,并且我无法在主线程中显示警报。
  • 是的,因此不需要任何警报。这就是为什么我在这个答案中告诉我这是我的情况。对您而言,您可以在与后台线程不同的线程中执行应用程序崩溃时的操作,并在完成任务后立即关闭该新线程
【解决方案3】:
- (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];
}

}

【讨论】:

    猜你喜欢
    • 2015-06-02
    • 1970-01-01
    • 1970-01-01
    • 2014-06-16
    • 2014-04-15
    • 1970-01-01
    • 1970-01-01
    • 2012-09-22
    • 1970-01-01
    相关资源
    最近更新 更多