这篇文章主要介绍了IOS 开发获取本地图片路径及上传的相关资料,需要的朋友可以参考下
1、获取沙盒路径
 NSString *path_document=NSHomeDirectory();
//设置存储文件路径!!!!!!文件路径的名字一定要区分开
  NSString *imagePath=[path_document stringByAppendingString:[NSString stringWithFormat:@"/Documents/%@%@%@.png",_shopObj.shopPicture,_shopObj.shopColor,self.shopObj.shopName]];
//写入文件
  [UIImagePNGRepresentation(img) writeToFile:imagePath atomically:YES];
//将地址存储到自己设置的Model模型中
  self.shopObj.shopPicture=imagePath;
2、读取数据的时候,直接从自己设置文件中读取出来就行了,例子如下:
 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;
  顺便说一下设置的根目录的位置:
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();
感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!
				 织梦狗教程
				
			本文标题为:IOS 开发获取本地图片路径及上传
				
        
 
            
        基础教程推荐
             猜你喜欢
        
	     - Android多返回栈技术 2023-04-15
 - Android中的webview监听每次URL变化实例 2023-01-23
 - Android开发使用RecyclerView添加点击事件实例详解 2023-06-15
 - Flutter手势密码的实现示例(附demo) 2023-04-11
 - IOS应用内跳转系统设置相关界面的方法 2022-11-20
 - android studio按钮监听的5种方法实例详解 2023-01-12
 - IOS 播放系统提示音使用总结(AudioToolbox) 2023-03-01
 - 解决Android Studio突然不显示logcat日志的问题 2023-02-04
 - iOS开发教程之XLForm的基本使用方法 2023-05-01
 - Flutter绘图组件之CustomPaint使用详解 2023-05-12
 
    	
    	
    	
    	
    	
    	
    	
    	
						
						
						
						
						
				
				
				
				