[super viewDidLoad]; 
    // 获取App的Sandbox路径 
    NSString *sandboxPath = NSHomeDirectory(); 
    NSLog(@"%@",sandboxPath); 
    //获取Documents路径 
    NSString *doc = [sandboxPath stringByAppendingPathComponent:@"Documents"]; 
    NSLog(@"doc:%@",doc); 
    //另一种获取Documents路径的方式 
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
    NSString *doc1 = [paths firstObject]; 
    NSLog(@"Doc:%@",doc1); 
     
    //获取Library的路径 
    NSString *lib = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) firstObject]; 
    NSLog(@"%@",lib); 
      
    //获取Library下的Caches目录 
    NSString *caches = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES)firstObject]; 
    NSLog(@"Caches:%@",caches); 
      
    //获取临时目录下tmp 
    NSString *tmp = NSTemporaryDirectory(); 
    NSLog(@"tmp:%@",tmp); 
      
    //如何获取应用程序本身的路径 
    NSBundle *mainBundle = [NSBundle mainBundle];//mainBundle 对象代表应用程序本身的内容 
    NSString *path = [mainBundle pathForResource:@"a" ofType:@"jpg"]; 
    NSLog(@"%@",path); 
    //获取Url 
    NSURL *url = [mainBundle URLForResource:@"a" withExtension:@"jpg"]; 
    NSLog(@"url:%@",url);

发布评论

分享到:

IT虾米网

微信公众号号:IT虾米 (左侧二维码扫一扫)欢迎添加!

iOS 绘制饼图代码详解
你是第一个吃螃蟹的人
发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。