2017-06-26 6 views
1

iPhone用iOSの10.3とAPFSのリリース以来、とデバイスメモリのサイズを取得:NSFileSystemSizeリターン工場のメモリサイズ - Objective-Cの

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSDictionary *dictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[paths lastObject] error: &error]; 
NSNumber *fileSystemSizeInBytes = [dictionary objectForKey: NSFileSystemSize]; 
NSUInteger totalDeviceSpace = [fileSystemSizeInBytes unsignedLongLongValue]; 
NSUInteger totalDeviceFreeSpace = [freeFileSystemSizeInBytes unsignedLongLongValue]; 

リターン工場メモリサイズ。たとえば、iOS 10.2では、16 Goデバイスで11,60 Goを取得しました。 10.3以上で15,99ゴー(stringFromByteCountでフォーマットされた結果)が得られます。

古い動作を復元するにはどうすればよいですか?

ありがとうございました!あなたはこの方法で合計領域と空き領域を取得する可能性があります

答えて

1

NSError *error = nil; 
NSArray *mypath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); 
NSDictionary *myDictionary = [[NSFileManager defaultManager] attributesOfFileSystemForPath:[mypath lastObject] error: &error]; 
NSNumber *fileSystemSizeInBytes = [myDictionary objectForKey: NSFileSystemSize]; 
NSNumber *freeFileSystemSizeInBytes = [myDictionary objectForKey:NSFileSystemFreeSize]; 
uint64_t totalSpaceSize = [fileSystemSizeInBytes unsignedLongLongValue]; 
uint64_t totalFreeSpaceSize = [freeFileSystemSizeInBytes unsignedLongLongValue]; 
+0

、私の編集したコード – Synny

+1

は何あなたがNSFileSystemFreeSizeを使用していない見ません。あなたはNSFileSystemSizeですが、私はあなたにその違いを示すために両方を書きました。 – Meikiem

+0

確かに動作し、テストし、結果を教えてください。 – Meikiem

0

だから、それが今のiOS 10.3、10.3.1、10.3.2およびiOSの11ベータ1でテストしたい振舞に(だと思われます2)。 は、私がインストールされたiOSのバージョンに応じて、結果を調整するには:

私は正確に何
NSOperatingSystemVersion ios10_3 = (NSOperatingSystemVersion){10, 3, 0}; 


if ([[NSProcessInfo processInfo] isOperatingSystemAtLeastVersion:ios10_3]) { 

    //User have at least 10.3 installed 

}else { 

    //below iOS 10.3 

}