iOS 错误 : request (0x_) other than the current request(0x0) signalled it was complete on connection 0x_

标签 ios objective-c ftp

我正在使用 Nico Kreipke 的 FTPManager ( click here to go to GiHub ) 从 FTP 地址下载一些数据。

如果代码在用户第一次交互之前运行,则它可以工作,之后它通常会失败(大约 10 次中有 9 次)。

失败时,将写入以下消息(0x_ 实际上是有效地址):

request (0x_) other than the current request(0x0) signalled it was complete on connection 0x_

该消息不是由我的代码或 FTPManager 编写的,而是由 Apple 编写的。在它的GitHub上,我发现了一个有同样错误的,但它的来源可能和我的一样。 (那个人没有使用 ARC。)

如果我尝试使用 po 命令打印这些地址的对象,控制台会显示没有可用的描述。

此外,内存会不断增加,直到应用收到内存警告,并且在操作系统终止它后不久。

通过在出现该消息时暂停应用程序,我可以看到主线程处于运行循环中。

CFRunLoopRun();

代码

self.ftpManager = [[FTPManager alloc] init];
[self downloadFTPFiles:@"192.168.2.1/sda1/1668"];

ftpManager是一个强引用。

downloadFTPFiles: 方法:

- (void) downloadFTPFiles:(NSString*) basePath
{
    NSLog(@"Reading contents of path: %@", basePath);

    FMServer* server = [FMServer serverWithDestination: basePath username:@"test" password:@"test"];

    NSArray* serverData = [self.ftpManager contentsOfServer:server];

    NSLog(@"Number of items: %d", serverData.count);

    for(int i=0; i < serverData.count; i++)
    {
        NSDictionary * sDataI = serverData[i];
        NSString* name = [sDataI objectForKey:(id)kCFFTPResourceName];
        NSNumber* type = [sDataI objectForKey:(id)kCFFTPResourceType];

        if([type intValue] == 4)
        {
            NSLog(@"%@ is Folder", name);
            NSString * nextDestination = [basePath stringByAppendingPathComponent: name];
            [self downloadFTPFiles:nextDestination];
        }
        else
        {
            NSLog(@"%@ is File", name);
            [self.ftpManager downloadFile:name toDirectory:[NSURL fileURLWithPath:NSHomeDirectory()] fromServer:server];
        }
    }
}

我做了什么

我已经尝试在几个地方运行该代码:

  • 应用委托(delegate)的application:didFinishLaunchingWithOptions:;

  • viewDidLoadviewWillAppear:viewDidAppear: 是在应用程序启动后立即加载的 View Controller 和 View Controller 稍后呈现。

  • 通过按钮事件触发的操作。

当委托(delegate)或加载了应用程序的 View Controller 执行时,数据下载总是能很好地执行(有一个异常(exception))。但是,当在用户与应用程序首次交互后运行时,它很可能会因上述错误而失败。

在用户第一次交互之前加载的 View Controller 的异常(exception)情况是调用在 viewWillAppear:viewDidAppear: 方法中。当它被第二次调用时(例如,标签栏 Controller 的标签),它也很可能会失败。

问题

有没有人知道可能会发生什么,或者我是否做错了什么?或者任何替代解决方案,也许?

欢迎任何解决此问题的帮助。

谢谢,
蒂亚戈

最佳答案

我最终在 dispatch_async block 中发送了 downloadFile:toDirectory:fromServer: 消息。我还为每个下载的文件创建了一个 FTPManage。

成功了,但我不知道为什么。

我把这个答案留给遇到这个问题的人。

如果有人能让我知道为什么这项技术有效,请在下面发表评论,以便我更新答案。

这是我下载每个文件的新方式:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
    FTPManager *manager = [[FTPManager alloc] init];
    [manager downloadFile:name toDirectory:[NSURL fileURLWithPath:path] fromServer:server];
});

再一次,如果你知道为什么这有效,请告诉我。

谢谢。

完整方法

- (void) downloadFTPFiles:(NSString*) basePath
{
    NSLog(@"Reading contents of path: %@", basePath);

    FMServer *server = [FMServer serverWithDestination:basePath username:@"test" password:@"test"];

    NSArray *serverData = [self.ftpManager contentsOfServer:server];

    NSLog(@"Number of items: %d", serverData.count);

    for(int i=0; i < serverData.count; i++)
    {
        NSDictionary *sDataI = serverData[i];
        NSString *name = [sDataI objectForKey:(id)kCFFTPResourceName];
        NSNumber *type = [sDataI objectForKey:(id)kCFFTPResourceType];

        if([type intValue] == 4)
        {
            NSLog(@"%@ is Folder", name);
            NSString *nextDestination = [basePath stringByAppendingPathComponent:name];
            [self downloadFTPFiles:nextDestination];
        }
        else
        {
            NSLog(@"%@ is File", name);
            dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
                FTPManager *manager = [[FTPManager alloc] init];
                [manager downloadFile:name toDirectory:[NSURL fileURLWithPath:path] fromServer:server];
            });
        }
    }
}

关于iOS 错误 : request (0x_) other than the current request(0x0) signalled it was complete on connection 0x_,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19325572/

相关文章:

ios - 标识符为 ... 的应用程序组不可用。请输入不同的字符串

iphone - 删除核心数据对象时如何处理外部数据的清理

php - PHP 上传和 MySQL 插入后的白色空图像

c# - 从远程客户端接收文件

ios - 使用 ARC 时如何调试 EXC_BAD_ACCESS code=2

iphone - UI导航栏标题

ios - performFetchWithCompletionHandler 永远不会被解雇

iphone - 推送/呈现模态视图 Controller

chdir 在 c 代码下的 unix 中不起作用,总是无法更改目录

iphone - NSScanner 适用于 WiFi 但不适用于 3G