开发者

iPhone - downloading images to app directory

开发者 https://www.devze.com 2023-02-12 21:00 出处:网络
I could really use some help with file开发者_运维百科s (images) download/save application process.

I could really use some help with file开发者_运维百科s (images) download/save application process.

I need some methods to:

  • Create hidden (accessable from my app only) directory
  • Save files (images + maybe 1 XML file) to such directory
  • List all of these directories and later list all files the selected directory contains

I know how to do it on Android, however on iPhone it seems a bit unclear.


Use this code to obtain your application's Documents directory path. This directory is only accessible from your application.

- (NSString *)applicationDocumentsDirectory {

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *basePath = ([paths count] > 0) ? [paths objectAtIndex:0] : nil;
return basePath;
}

To save and load files from there, you can use any of a wide range of methods, from C functions (fopen and the like) to Cocoa convenience methods like NSString's

- (BOOL)writeToFile:(NSString *)path atomically:(BOOL)useAuxiliaryFile encoding:(NSStringEncoding)enc error:(NSError **)error
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号