iOS 通过Core Foundation 获取Bundle路径

iOS 上支持调用C库来获取.app的Bundle路径,实现代码如下:

#include

// Get a reference to the main bundle

CFBundleRefmainBundle=CFBundleGetMainBundle();

// Get a reference to the file's

URLCFURLRefimageURL=CFBundleCopyResourceURL(mainBundle,CFSTR("MyImage"),CFSTR("bmp"),NULL);

// Convert the URL reference into a string reference

CFStringRefimagePath=CFURLCopyFileSystemPath(imageURL,kCFURLPOSIXPathStyle);

// Get the system encoding method

CFStringEncodingencodingMethod=CFStringGetSystemEncoding();

// Convert the string reference into a C string

constchar*path=CFStringGetCStringPtr(imagePath,encodingMethod);

fprintf(stderr,"File is located at %s\n",path);


Reference From:

https://stackoverflow.com/questions/8768217/how-can-i-find-the-path-to-a-file-in-an-application-bundle-nsbundle-using-c

你可能感兴趣的:(iOS 通过Core Foundation 获取Bundle路径)