iphone开发返回Documents Tmp 应用程序资源文件夹路径
来源:互联网 发布:陈道明 深夜食堂 知乎 编辑:程序博客网 时间:2024/05/18 22:53
大伙都知道iphone开发下要经常返回文件夹的路径,但是苹果提供的api返回不同的文件夹又不一样,我在这里统一定义下接口,
以后无论是返回Documents还是Tmp还是应用程序资源文件夹路径都只要直接调用:
[self dataFilePath:@"data.plist" ofType:kDocuments]
下面是源代码:
#define kDocuments 1 /*返回应用程序沙盒下documents文件夹里的文件路径*/#define kTmp 2 /*返回应用程序沙盒下Tmp文件夹里的文件路径*/#define kAPP 3 /*返回应用程序沙盒下app文件夹里的文件路径*/
- (NSString *)dataFilePath:(NSString *)file ofType:(int)kType{ NSString *pathFile = nil; switch (kType) { case kDocuments: { // NSDocumentDirectory代表查找Documents路径,NSUserDomainMask代表在应用程序沙盒下找 NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); // ios下Documents文件夹只有一个 NSString *documentsDirectory = [paths objectAtIndex:0]; pathFile = [documentsDirectory stringByAppendingPathComponent:file]; break; } case kTmp: { NSString *str = NSTemporaryDirectory(); pathFile = [str stringByAppendingPathComponent:file]; break; } case kAPP: { // 获得文件名 NSString *str =[file stringByDeletingPathExtension]; // 获得文件扩展路径 NSString *str2 = [file pathExtension]; pathFile = [[NSBundle mainBundle] pathForResource:str ofType:str2]; break; } default: break; } return pathFile;}
- iphone开发返回Documents Tmp 应用程序资源文件夹路径
- iphone开发中获取Documents文件夹和资源文件夹路径
- 获取documents路径 iphone
- 关于ios获取本地Documents路径,没有Documents文件夹
- 文件夹路径my documents 含有无效字符
- 寻找沙箱的Documents文件夹路径
- Iphone文件处理——使用Documents文件夹
- 开发iPhone应用程序(一)
- iphone应用程序开发指南
- 返回选择文件夹的路径
- iphone 开发资源
- iphone开发资源汇总
- iphone开发资源汇总
- iphone开发资源汇总
- IPhone开发资源汇总
- iphone开发资源汇总
- iPhone开发资源汇总
- iPhone开发资源汇总
- Subversion Edge
- java.math.BinInteger和java.math.BigDecimal
- 搜索引擎基本工作原理
- Oracle公司的历史发展
- LGame引擎学习之一(未续完)
- iphone开发返回Documents Tmp 应用程序资源文件夹路径
- 在数组里查找这样的数,它大于等于左侧所有数,小于等于右侧所有数
- 推荐一系列优秀的Android开发源码
- Java关键字介绍之final
- (dum(b)ug)
- 今天的电商价格大战,京东,国美,苏宁到底谁赢了,还是都输了?
- Python的异常处理机制
- 一个合格的程序员应该读过哪些书
- shell