美文网首页
iOS 通过Core Foundation 获取Bundle路

iOS 通过Core Foundation 获取Bundle路

作者: 飙车Dave | 来源:发表于2017-07-04 17:15 被阅读0次

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

相关文章

网友评论

      本文标题:iOS 通过Core Foundation 获取Bundle路

      本文链接:https://www.haomeiwen.com/subject/wjexhxtx.html