IOS获取资源路径

  1. 获取已经添加到xcode工程中的某一资源文件 file.txt 的路径

NSString *filePath_= [[NSBundle mainBundle] pathForResource:@"file" ofType:@"txt"];
std::string filePath =std::string([filePath_ UTF8String]);

 

2. 对当前xcode工程开通沙盒权限后,访问存储到手机上的某一资源文件夹sources/file.txt的路径

    NSString *docDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject];
    NSString *fileDir = [docDir stringByAppendingPathComponent:@"sources"];
    NSString *filePath = [fileDir stringByAppendingPathComponent:@"file.txt"];

    std::string filePath_=std::string([filePath UTF8String]);

 

posted @ 2019-04-09 21:11  一度逍遥  阅读(2404)  评论(1编辑  收藏  举报