ã¢ããªã±ã¼ã·ã§ã³ãã£ã¬ã¯ããªã®æ§é ã¨ã¢ã¯ã»ã¹æ¹æ³
iOSã§ã¯ãã¼ã¿ã®ä¿åå ´æã¨ãã¦ç¹å®ã®ãã£ã¬ã¯ããªãå©ç¨ãããã¨ãã§ãã¾ãã
Best Albumã§ã¯ãµã ãã¤ã«ç»åããªãªã¸ãã«ç»åãå
¨ã¦ãã£ãã·ã¥ãã£ã¬ã¯ããªã«ä¿åãã¦ããã®ã§ãããããã©ã¼ãã³ã¹çã«å
¨ãåé¡ããªããä»å¾æ´»ç¨ããæ©ä¼ãå¢ããããªã®ã§ã¾ã¨ãã¦ããã¾ãã
ãã£ã¬ã¯ããªæ§é
/Documents
ã¢ããªåºæã®ãã¼ã¿ãã¡ã¤ã«ãä¿åãããã£ã¬ã¯ã㪠(ããã¯ã¢ããããã)
/Library/Preferences
ã¢ããªåºæã®ç°å¢è¨å®ãã¡ã¤ã«ãä¿åãããã£ã¬ã¯ã㪠(ããã¯ã¢ããããã)
NSUserDefaults or CFPreferencesAPIçµç±ã§èªã¿æ¸ããã
/Library/Caches
ã¢ããªåºæã®ãµãã¼ããã¡ã¤ã«ãä¿åãããã£ã¬ã¯ã㪠(ããã¯ã¢ãããããªã)
/tmp
ä¸æãã¡ã¤ã«ãä¿åãããã£ã¬ã¯ã㪠(ããã¯ã¢ãããããªã)
ãã¹ã®åå¾
ä¸è¨ãã£ã¬ã¯ããªã®ãã¡ãPreferencesã¯ç´æ¥ã¢ã¯ã»ã¹ãã¦ã¯ã ãã§ãtmpé ä¸ã«ããã¦ãèªåã§ã¯ãªã¼ã³ã¢ãããããªããããå®éã«å©ç¨ããã®ã¯Documentsã¨Cachesã®2ã¤ã§ååãã¨æãã¾ããããããã®ãã¹åå¾ã¯ä¸è¨ã®éãã§ãã
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); NSString *dir = [paths objectAtIndex:0]; NSLog(@"%@", dir);
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *dir = [paths objectAtIndex:0]; NSLog(@"%@", dir);
ãã¹ã®é£çµ
å°ç¨ã®ã¡ã½ãããæºåããã¦ãã¾ãã
NSString *dirA = [dir stringByAppendingPathComponent:@"dirA"]; NSString *pathA = [dirA stringByAppendingPathComponent:@"image.png"]; NSLog(@"%@", pathA); NSString *dirB = [dir stringByAppendingPathComponent:@"dirB"]; NSString *pathB = [dirB stringByAppendingPathComponent:@"image.png"]; NSLog(@"%@", pathB);
ãã£ã¬ã¯ããªã®æä½
FileManagerçµç±ã§æä½ã§ãã¾ãã
NSFileManager *fm = [NSFileManager defaultManager]; NSError *error; // ãã§ã㯠[fm fileExistsAtPath:dirA]; // ä½æ [fm createDirectoryAtPath:dirA withIntermediateDirectories:YES attributes:nil error:&error]; // 移å [fm moveItemAtPath:dirA toPath:dirB error:&error]; // ã³ãã¼ [fm copyItemAtPath:dirA toPath:dirB error:&error]; // åé¤ [fm removeItemAtPath:dirA error:&error];
ãã¡ã¤ã«ã®æä½
ãã¡ã¤ã«ãåããã
// ä½æ NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://xxx/xxx.png"]]; [fm createFileAtPath:pathA contents:data attributes:nil]; // åé¤ [fm removeItemAtPath:pathA error:&error]; // 移å [fm moveItemAtPath:pathA toPath:pathB error:&error]; // ã³ãã¼ [fm copyItemAtPath:pathA toPath:pathB error:&error];
ãã¡ã¤ã«ãµã¤ãºã®åå¾
ä»ã©ãããããã£ãã·ã¥ã§å©ç¨ãã¦ããããã§ãã¯ãããå ´åã¯ãã®ãããªæãã§ãã§ãã¯å¯è½ã§ããCachesãã£ã¬ã¯ããªé ä¸ã®ãµã¤ãºãbyteã§è¿ã£ã¦ãã¾ãã
- (unsigned long long int)countCacheSize{ unsigned long long int cacheSize = 0; NSFileManager *fm = [NSFileManager defaultManager]; NSError *error; NSArray *cachePaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES); NSString *cacheDirectory = [cachePaths objectAtIndex:0]; NSArray *cacheFileList = [fm subpathsAtPath:cacheDirectory]; NSEnumerator *cacheEnumerator = [cacheFileList objectEnumerator]; NSString *cacheFilePath; while (cacheFilePath = [cacheEnumerator nextObject]) { NSString *path = [cacheDirectory stringByAppendingPathComponent:cacheFilePath]; NSDictionary *cacheFileAttributes = [fm attributesOfItemAtPath:path error:&error]; cacheSize += [cacheFileAttributes fileSize]; } NSLog(@"%llu", cacheSize); return cacheSize; }