0

重複の可能性:
iPhone / iPadデバイスの使用可能な/空きディスク容量の合計を検出するにはどうすればよいですか?

iOSアプリでiOSデバイスの次の詳細を取得したいと思います。Googleで検索しましたが、これらのアイデアは見つかりませんでした。

  1. フォーマットされたスペース
  2. 使用済みスペース
  3. フリースペース
4

4 に答える 4

1

statfs への C システム コールを作成します。

参照: https://developer.apple.com/library/mac/#documentation/Darwin/Reference/ManPages/man2/statfs.2.html

そしてこのSOの答え: ファイルをダウンロードする前にiPhoneデバイスの十分なスペースを確認してください

于 2012-12-24T12:06:58.980 に答える
1

合計および空き容量の場合、このメソッドは freeSpace を返します

- (uint64_t)freeDiskspace{
    uint64_t totalSpace = 0;
    uint64_t totalFreeSpace = 0;

    __autoreleasing NSError *error = nil;  
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);  
    NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error];  

   if (dictionary) {  
       NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize];  
       NSNumber *freeFileSystemSizeInBytes = [dictionary objectForKey:NSFileSystemFreeSize];
      totalSpace = [fileSystemSizeInBytes unsignedLongLongValue];
      totalFreeSpace = [freeFileSystemSizeInBytes unsignedLongLongValue];
      NSLog(@"Memory Capacity of %llu MiB with %llu MiB Free memory available.", ((totalSpace/1024ll)/1024ll), ((totalFreeSpace/1024ll)/1024ll));
   }
   else {  
      NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %d", [error domain], [error code]);  
   }  

   return totalFreeSpace;
}
于 2012-12-24T12:07:36.343 に答える
0

これらはuidevice-extensionを使用して取得でき ます。必要なのは次の関数です。

- (NSNumber *) totalDiskSpace;
- (NSNumber *) freeDiskSpace;

UIDevice-Hardware.h から

于 2012-12-24T12:07:15.440 に答える
0

NSFileManager とメソッドを使用することもできます

- (NSDictionary *)attributesOfFileSystemForPath:(NSString *)path error:(NSError **)error

データを送信したいパス上。この方法は statfs を使用します(他の回答で言及されています)。

于 2012-12-24T12:09:22.210 に答える