app路径 c函数获取ios
2011-12-26 13:46:00 weixin_30234243 阅读数 1

 

    //根据文件名来获取文件路径  doucument
- (NSString *)dataFilePath:(NSString *)sender {
NSArray *path = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,
NSUserDomainMask,
YES);
NSString *documentDirectory = [path objectAtIndex:0];
return [documentDirectory stringByAppendingPathComponent:sender];
}

 

NSString *defaultDBPath = [[[NSBundle mainBundle] resourcePath] stringByAppendingPathComponent:filename]; //资源目录

 

NSArray *cache = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);     //caches目录
NSString *cachePath = [cache objectAtIndex:0] ;

NSString *voiceName = [cachePath stringByAppendingPathComponent:[sender stringByAppendingString:@".wav"]];




转载于:https://www.cnblogs.com/ligun123/archive/2011/12/26/2301993.html

2017-08-02 12:00:00 weixin_33830216 阅读数 56

let bundlePath =Bundle.main.bundlePath

let homeDir =NSHomeDirectory()

let tmpDir =NSTemporaryDirectory()

print("NSDocumentDirectory")

if let docDir =FileManager.default.urls(for:FileManager.SearchPathDirectory.documentDirectory, in:FileManager.SearchPathDomainMask.userDomainMask).first{

print(docDir)

}

print(NSSearchPathForDirectoriesInDomains(FileManager.SearchPathDirectory.documentDirectory,FileManager.SearchPathDomainMask.userDomainMask,true))

print("NSLibraryDirectory")

if let libDir =FileManager.default.urls(for: .libraryDirectory, in: .userDomainMask).first{

print(libDir)

}

print(NSSearchPathForDirectoriesInDomains(.libraryDirectory, .userDomainMask,true).first??"Not Found")

print("NSCachesDirectory")

print(NSSearchPathForDirectoriesInDomains(.cachesDirectory, .userDomainMask, true).first??"Not Found")

print("NSTemporaryDirectory")

print(NSTemporaryDirectory())

2012-11-12 19:24:00 weixin_34115824 阅读数 1

【问题描述】

iOS应用中,主要有两种路径,一是Documents目录(即应用安装的路径),二是Bundle路径(即应用程序束)

一、获取Documents路径

- (NSString *)filePathInDoc:(NSString *)filename
{
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *documentDirectory=[paths objectAtIndex:0];
    return [documentDirectory stringByAppendingPathComponent:filename];
}

那么获取Doc目录下的文件Text.txt,如下:

[self filePathInDoc:@"Text.txt"];

 

二、获取Bundle路径

- (NSString *)getFilePathInBundle:(NSString *)filename
{
    NSString *nameWithoutExt = [filename stringByDeletingPathExtension];
    NSString *ext = [filename pathExtension];
    return [[NSBundle mainBundle] pathForResource:nameWithoutExt ofType:ext];
}

 

//- (NSString *)filePathInBundle:(NSString *)filename
//{
//    int index = -1;
//    
//    for (int loop = [filename length] - 1; loop >= 0; loop--)
//    {
//        if ([filename characterAtIndex:loop] == '.')
//        {
//            index = loop;
//            break;
//        }
//    }
//    
//    if (index == -1)
//    {
//        return nil;
//    }
//    
//    NSString *filenameWithoutExt = [filename substringToIndex:index];
//    NSString *ext = [filename substringFromIndex:index + 1];
//    NSString *path = [[NSBundle mainBundle] pathForResource:filenameWithoutExt ofType:ext];
//    return path;
//}

那么获取Bundle下的Text.txt文件,如下:

[self filePathInBundle:@"Text.txt"];

转载于:https://www.cnblogs.com/ftrako/archive/2012/11/12/2766884.html

2015-09-07 15:49:45 D_origin 阅读数 187

获取这些目录路径方法:

1,获取家目录路径函数:

NSString*homeDir = NSHomeDirectory();

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();

5,获取应用程序程序包中资源文件路径方法:

例如获取程序包中一个图片资源(apple.png)路径方法:

NSString*imagePath = [[NSBundle mainBundle] pathForResource:@”apple” ofType:@”png”];

UIImage*appleImage = [[UIImage alloc] initWithContentsOfFile:imagePath];

代码中mainBundle类方法用于返回一个代表应用程序包对象。

2012-11-12 19:24:00 weixin_34345560 阅读数 3

【问题描述】

iOS应用中,主要有两种路径,一是Documents目录(即应用安装的路径),二是Bundle路径(即应用程序束)

一、获取Documents路径

- (NSString *)filePathInDoc:(NSString *)filename
{
    NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString *documentDirectory=[paths objectAtIndex:0];
    return [documentDirectory stringByAppendingPathComponent:filename];
}

那么获取Doc目录下的文件Text.txt,如下:

[self filePathInDoc:@"Text.txt"];

 

二、获取Bundle路径

- (NSString *)getFilePathInBundle:(NSString *)filename
{
    NSString *nameWithoutExt = [filename stringByDeletingPathExtension];
    NSString *ext = [filename pathExtension];
    return [[NSBundle mainBundle] pathForResource:nameWithoutExt ofType:ext];
}

 

//- (NSString *)filePathInBundle:(NSString *)filename
//{
//    int index = -1;
//    
//    for (int loop = [filename length] - 1; loop >= 0; loop--)
//    {
//        if ([filename characterAtIndex:loop] == '.')
//        {
//            index = loop;
//            break;
//        }
//    }
//    
//    if (index == -1)
//    {
//        return nil;
//    }
//    
//    NSString *filenameWithoutExt = [filename substringToIndex:index];
//    NSString *ext = [filename substringFromIndex:index + 1];
//    NSString *path = [[NSBundle mainBundle] pathForResource:filenameWithoutExt ofType:ext];
//    return path;
//}

那么获取Bundle下的Text.txt文件,如下:

[self filePathInBundle:@"Text.txt"];

转载于:https://www.cnblogs.com/ftrako/archive/2012/11/12/2766884.html

IOS App资源路径

阅读数 559

iOS App各种路径

阅读数 1839

IOS APP 路径资源

阅读数 249

IOS App资源路径

阅读数 9390

没有更多推荐了,返回首页