[英]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.