Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/106.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
Ios 将文件夹添加到iPad捆绑包在模拟器上工作,而不是在设备上_Ios_Ipad_Directory_Bundle_Target - Fatal编程技术网

Ios 将文件夹添加到iPad捆绑包在模拟器上工作,而不是在设备上

Ios 将文件夹添加到iPad捆绑包在模拟器上工作,而不是在设备上,ios,ipad,directory,bundle,target,Ios,Ipad,Directory,Bundle,Target,我的应用程序有两个目标。 每个文件都有自己的Info.plist文件和一个自定义文件夹,作为引用而不是组包含。 当我在模拟器上运行我的目标时,文件夹被正确地插入到包中,其中的文件被毫无问题地读取。 以下是读取文件夹路径的代码: NSBundle* mainBundle; NSString *fileFolder; mainBundle = [NSBundle mainBundle]; NSLog(@"Bundle path: %@", [mainBundle bundlePath]); NSLo

我的应用程序有两个目标。 每个文件都有自己的Info.plist文件和一个自定义文件夹,作为引用而不是组包含。 当我在模拟器上运行我的目标时,文件夹被正确地插入到包中,其中的文件被毫无问题地读取。 以下是读取文件夹路径的代码:

NSBundle* mainBundle;
NSString *fileFolder;
mainBundle = [NSBundle mainBundle];
NSLog(@"Bundle path: %@", [mainBundle bundlePath]);
NSLog(@"Folder name: %@", [mainBundle objectForInfoDictionaryKey:@"CustomFolder"]);
NSString *folder = [mainBundle objectForInfoDictionaryKey:@"CustomFolder"];
fileFolder = [[[NSBundle mainBundle] pathForResource:folder ofType:nil] retain];
NSLog(@"Folder: %@", fileFolder);
如果我尝试在设备上调试应用程序,则捆绑路径和文件夹名称正确,但文件夹字符串为空。 我已经检查了我的应用程序产品内部,找到了正确的文件夹,其中包含所有文件。 那有什么问题?这是一个读取权限问题吗

更新 在iPad模拟器中运行的结果路径如下

/*/库/应用程序支持/iPhone模拟器/4.3.2/Applications/8337B9E5-1BFE-4A17-969E-E3E6E43193D6/MyApp.app/CustomFolder/

更新2 问题是我添加了文件夹,并为任何添加的文件夹创建了文件夹引用。
我用stringByAppendingPathComponent替换了pathForResource,但现在DirectoryAtPath子路径的问题仍然存在。

您必须确保在iPad内存中使用了正确的位置。在模拟器上保存内容的位置没有限制。此代码有效

+(NSString*) pathToDocumentsFolder
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
return documentsDirectory;  
}
+(NSString*) pathToFileInDocumentsFolder:(NSString*)filename
{
NSString *pathToDoc = [NSBundle pathToDocumentsFolder];
return [pathToDoc stringByAppendingPathComponent:filename];
}

这是一个案件敏感性问题吗?在Mac(包括iOS模拟器)上,文件系统不区分大小写,但它位于设备上。文件夹的名称和代码引用大小写相同。我的文件夹不在文档文件夹中,而是在捆绑包中。查看我发布的完整路径更新。您的iPhone上有什么版本的iOS?