开发者

Adding folder to iPad bundle works on simulator, not on device

开发者 https://www.devze.com 2023-04-04 21:44 出处:网络
I have two targets for my app. Each has its file own Info.plist and a custom folder included (as references, not as group).

I have two targets for my app.

Each has its file own Info.plist and a custom folder included (as references, not as group).

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 = [mainBu开发者_开发技巧ndle 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.

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

/*/Library/Application Support/iPhone Simulator/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".

I replaced pathForResource with stringByAppendingPathComponent, but the problem now persist for subpathsOfDirectoryAtPath.


You have to make sure you use the correct place in the iPad memory. 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];
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号