专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Iphone

iphone开发回到Documents Tmp 应用程序资源文件夹路径

发布时间:2010-05-30 01:02:56 文章来源:www.iduyao.cn 采编人员:星星草
iphone开发返回Documents Tmp 应用程序资源文件夹路径

大伙都知道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;
}


友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: