Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iPhone:可以访问模拟器中文档目录中的文件,但不能访问设备_Iphone_Iphone Sdk 3.0_Ios Simulator - Fatal编程技术网

iPhone:可以访问模拟器中文档目录中的文件,但不能访问设备

iPhone:可以访问模拟器中文档目录中的文件,但不能访问设备,iphone,iphone-sdk-3.0,ios-simulator,Iphone,Iphone Sdk 3.0,Ios Simulator,我正在编写一个应用程序,它将捆绑包的一些内容复制到应用程序文档的目录中,主要是图像和媒体。然后,我通过应用程序从文档目录访问此媒体 这在模拟器中完全可以正常工作,但在设备上却不行。资产显示为空。我已经完成了NSLog,文件的路径看起来是正确的,并且通过在控制台中转储一个文件列表来确认文件存在于目录中 有什么想法吗?谢谢大家! 编辑 下面是复制到文档目录的代码 NSString *pathToPublicationDirectory = [NSString stringWithFormat:@"i

我正在编写一个应用程序,它将捆绑包的一些内容复制到应用程序文档的目录中,主要是图像和媒体。然后,我通过应用程序从文档目录访问此媒体

这在模拟器中完全可以正常工作,但在设备上却不行。资产显示为空。我已经完成了NSLog,文件的路径看起来是正确的,并且通过在控制台中转储一个文件列表来确认文件存在于目录中

有什么想法吗?谢谢大家!

编辑

下面是复制到文档目录的代码

NSString *pathToPublicationDirectory = [NSString stringWithFormat:@"install/%d",[[[manifest objectAtIndex:i] valueForKey:@"publicationID"] intValue]];
    NSString *manifestPath = [[NSBundle mainBundle] pathForResource:@"content" ofType:@"xml" inDirectory:pathToPublicationDirectory];
    [self parsePublicationAt:manifestPath];

    // Get actual bundle path to publication folder
    NSString *bundlePath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:pathToPublicationDirectory];
    // Then build the destination path
    NSString *destinationPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d", [[[manifest objectAtIndex:i] valueForKey:@"publicationID"] intValue]]];

    NSError *error = nil;
    // If it already exists in the documents directory, delete it
    if ([fileManager fileExistsAtPath:destinationPath]) {
        [fileManager removeItemAtPath:destinationPath error:&error];
    }
    // Copy publication folder to documents directory
    [fileManager copyItemAtPath:bundlePath toPath:destinationPath error:&error];
我正在用这个方法计算docs目录的路径:

- (NSString *)applicationDocumentsDirectory {
return [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
}

这里有一个例子,我是如何建立一个通往图像的路径的

path = [NSString stringWithFormat:@"%@/%d/%@", [self applicationDocumentsDirectory], [[thisItem valueForKey:@"publicationID"] intValue], [thisItem valueForKey:@"coverImage"]];

我看不到
文档目录的定义位置

NSString *destinationPath = [documentsDirectory stringByAppendingPathComponent:[NSString stringWithFormat:@"%d", [[[manifest objectAtIndex:i] valueForKey:@"publicationID"] intValue]]];
也许下面的方法可以奏效

NSString *destinationPath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:[NSString stringWithFormat:@"%d", [[[manifest objectAtIndex:i] valueForKey:@"publicationID"] intValue]]];

您的复制代码看起来很好,并且您说没有错误

但是我对“资产只是显示为空”很感兴趣。你确定以后要用确切的相同的名称访问文件名吗


与模拟器不同,真正的iPhone有一个区分大小写的文件系统。

结果是,捆绑包没有在设备上更新,显然没有与模拟器相同的文件集。这篇博文有点帮助:


基本上,我清理了构建并删除了应用程序,并首先直接安装到设备上,而不是模拟器上。有趣的东西。

根据我的经验,模拟器对访问的限制较少。我相信我曾经遇到过这样的情况,模拟器让我直接写入包中。一些代码将有助于了解发生了什么。它是在前面定义的,很抱歉我遗漏了这一部分。NSString*documentsDirectory=[self-applicationDocumentsDirectory];如果没有定义,应用程序可能会崩溃。
parsePublicationAt:
做什么?它是在一个单独的线程上解析的吗?在设备上,它可能无法完成。在执行filemanager操作后检查错误将很有帮助<代码>NSLog(@“文件管理器错误:%@,[error localizedDescription])它在指定的位置解析一些XML。我查看了filemanager是否产生了错误,但它返回了true。我可以看到文件在documents目录中,所以看起来它们被复制的很好。谢谢啊,这很有趣,很高兴知道。当我们直接从包中访问时,它对我们有效,因此我们很高兴我们的文件名是正确的。谢谢你!