简体   繁体   English

将文件夹添加到iPad捆绑包适用于模拟器,而不适用于设备

[英]Adding folder to iPad bundle works on simulator, not on device

I have two targets for my app. 我的应用有两个目标。
Each has its file own Info.plist and a custom folder included (as references, not as group). 每个都有其自己的文件Info.plist和一个自定义文件夹(作为引用,而不是组)。
When I run my target on the simulator the folder is correctly inserted in the bundle and the files inside it are read without problems. 当我在模拟器上运行目标时,该文件夹已正确插入捆绑包中,并且可以毫无问题地读取其中的文件。
This is the code to read the folder path: 这是读取文件夹路径的代码:

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);

If I try to debug the app on the device, Bundle path and Folder name are correct, but the folder string is null. 如果我尝试在设备上调试该应用程序,则捆绑路径和文件夹名称正确,但是文件夹字符串为null。
I've checked inside my app product, and the there is the right folder, with all the files. 我已经检查了我的应用程序产品的内部,并找到了包含所有文件的正确文件夹。
So what's the problem? 所以有什么问题? Is it a read permission issue? 这是读取权限问题吗?

UPDATE The resulting path running in iPad Simulator is this 更新在iPad Simulator中运行的结果路径是这样

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

UPDATE 2 The problem is that I've added the folder with "Create folder references for any added folders". 更新2的问题是我添加了带有“为任何添加的文件夹创建文件夹引用”的文件夹。
I replaced pathForResource with stringByAppendingPathComponent, but the problem now persist for subpathsOfDirectoryAtPath. 我用stringByAppendingPathComponent替换了pathForResource,但是问题仍然存在于subpathsOfDirectoryAtPath。

You have to make sure you use the correct place in the iPad memory. 您必须确保使用iPad内存中的正确位置。 there is no restrictions to where you save stuff on the simulator. 在模拟器上保存内容的位置没有任何限制。 This code works 此代码有效

+(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];
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 JayData / Phonegap可在iPad Simulator中使用,但不适用于iPad设备 - JayData / Phonegap works in iPad Simulator but not iPad device UIWebView在Simulator中效果很好,但在iPad设备中效果不佳 - UIWebView works well in Simulator but not in iPad device iAd在模拟器上有效,但在设备上崩溃(ipad) - iAd works on simulator but crash on device(ipad) iOS 8.3 iPad上的自定义UIWindow可在模拟器上运行,但不能在设备上运行 - Custom UIWindow on iOS 8.3 iPad works on simulator but not device iPad Opengl ES程序可以在模拟器上正常运行,但不能在设备上运行 - iPad Opengl ES program works fine on simulator but not device 有一种方法可以访问 iphone/ipad 中的文档文件夹(真实设备,没有模拟器)? - There's a way to access the document folder in iphone/ipad (real device, no simulator)? AVExportSession可在Simulator,iPad 2而非iPad 4上运行 - AVExportSession works on Simulator, iPad 2 but not iPad 4 在iPad Simulator上可用,但在iPad上崩溃 - Works on iPad Simulator but crashes on iPad 一个奇怪的行为是QLPreviewer或iPad设备,一个docx文件没有在设备中打开但在模拟器(iPad和iPhone)中工作正常 - A weird behaviour is with QLPreviewer or iPad Device that one docx file is not getting opened in device but works fine in simulator (iPad and iPhone) 我的应用程序在iPad模拟器上运行良好,但在iPad(iOS 8.4)上崩溃了,xcode显示无法捆绑捆绑NIB - My app works well on iPad simulator but crashed on iPad(iOS 8.4) ,the xcode says Could not load NIB in bundle
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM