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