iOS 通过Core Foundation 获取Bundle路径

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

#include <CoreFoundation/CFBundle.h>

// 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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • **2014真题Directions:Read the following text. Choose the be...
    又是夜半惊坐起阅读 9,998评论 0 23
  • 他在渭水河边 栽下十里桃花 铸下一段长亭 只为久恋那股清风 那年,初见 还是寒冬 没有雪花舞动 却漾起了整个天空 ...
    xiao_ming小明阅读 185评论 1 3
  • 摘要:各家应用的广告架构可能各不相同,这张图是我为了更好的理解整体架构按照计算广告里的架构图稍做修改所得,有些细节...
    Wwwennnn阅读 1,969评论 0 3
  • 祁连山真是一个很温柔的山。 总之嘉峪关是让人真正理解祁连山的地方。祁连山就是水之源。从嘉峪关的各处都能看到这座山,...
    魔法密林港阅读 639评论 0 1