开发者

Can't search subdirs with CFBundleCopyResourceURL

I am working the iphone/ipad 3.开发者_Python百科2 SDK and have created a subdirectory named "Docs" under the default Resources directory "Resources-iPad". If I place "file.pdf" directly in the resources directory and make this call, all works well:

CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(),CFSTR("file.pdf"), NULL, NULL);

If I put "file.pdf" in the "Docs" subdirectory and per the Apple docs try this, the call returns NULL:

CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(),CFSTR("file.pdf"), NULL, CFSTR("Docs");

What have I done incorrectly?


Make sure the "Docs" subdirectory really is being included in your built application.

See path for resource in directory problem (using NS* calls instead of CF* ones, but similar issue)

You might also try splitting the name ("file") and type ("pdf"):

CFURLRef pdfURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(),CFSTR("file"), CFSTR("pdf"), CFSTR("Docs");


I ended up taking a different approach:

paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES); 
sharedDocs = [[paths objectAtIndex:0] stringByAppendingPathComponent:@"Docs"];
NSString  *filePath = [sharedDocs stringByAppendingPathComponent:fileName];
const UInt8 *pFilepath = (const UInt8 *)[filePath UTF8String];
CFURLRef pdfURL = CFURLCreateFromFileSystemRepresentation (NULL, pFilepath, strlen((const char*)pFilepath), false);
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜