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]);

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM