当前位置: 首页 > >

ios 获取各路径

发布时间:



因为各种需求,需要获取的路径不一致,故写下这文章,以作备忘。





- (NSString *)getDocumentPath
{
NSString *path = nil;

// Method 1
NSArray *pathsArray = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
path = [pathsArray objectAtIndex:0];

// Method 2
// path = [NSHomeDirectory() stringByAppendingPathComponent:@"Documents"];

return path;
}

- (NSString *)getAppPath
{
NSString *path = nil;

path = NSHomeDirectory();

return path;
}


// tmp 目录我们可以在里面写入一些程序运行时需要用得数据,里面写入得数据在程序退出后会没有。
- (NSString *)getTmpPath
{
NSString *path = nil;

path = NSTemporaryDirectory();

return path;
}

- (NSString *)getAppPackagePath
{
NSString *path = nil;

// Method 1
path = [[NSBundle mainBundle] resourcePath];

// Method 2

return path;
}

- (NSString *)getFilePath
{
NSString *path = nil;

NSFileManager *fileManager = [NSFileManager defaultManager];
NSURL *pathURL = [fileManager URLForDirectory:NSApplicationSupportDirectory inDomain:NSUserDomainMask appropriateForURL:nil create:YES error:NULL];
path = [pathURL path];

return path;
}







友情链接: