亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

IOS  開發(fā)獲取本地圖片路徑及上傳

 更新時(shí)間:2017年05月12日 14:27:07   作者:冉然  
這篇文章主要介紹了IOS 開發(fā)獲取本地圖片路徑及上傳的相關(guān)資料,需要的朋友可以參考下

1、獲取沙盒路徑

 NSString *path_document=NSHomeDirectory();
//設(shè)置存儲(chǔ)文件路徑!?。。。?!文件路徑的名字一定要區(qū)分開
  NSString *imagePath=[path_document stringByAppendingString:[NSString stringWithFormat:@"/Documents/%@%@%@.png",_shopObj.shopPicture,_shopObj.shopColor,self.shopObj.shopName]];
//寫入文件
  [UIImagePNGRepresentation(img) writeToFile:imagePath atomically:YES];
//將地址存儲(chǔ)到自己設(shè)置的Model模型中
  self.shopObj.shopPicture=imagePath;

2、讀取數(shù)據(jù)的時(shí)候,直接從自己設(shè)置文件中讀取出來(lái)就行了,例子如下:

 NSString *path_document=NSHomeDirectory();
  NSString *imagePath=[path_document stringByAppendingString:[NSString stringWithFormat:@"/Documents/%@%@%@.png",_shopObj.shopPicture,_shopObj.shopColor,self.shopObj.shopName]];
  UIImage *img=[UIImage imageWithContentsOfFile:imagePath];
  cell.imgV.image=img;

  順便說(shuō)一下設(shè)置的根目錄的位置:

2,獲取Documents目錄路徑的方法:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *docDir = [paths objectAtIndex:0];

3,獲取Caches目錄路徑的方法:

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
NSString *cachesDir = [paths objectAtIndex:0];

4,獲取tmp目錄路徑的方法:

NSString *tmpDir = NSTemporaryDirectory();

感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論