2011-11-23 27 views
2

デバイス名、タイプ、ディスク内のスペース、iOSバージョンなどのデバイス情報を読み取るために、このタスクを実行します。私は、デバイスがiPad、iPhone、または網膜であるかどうかを知るためのいくつかの方法を持っていますが、デバイスについてさらに知っていることは一目瞭然です。Cocoa touch - 取得デバイス情報

答えて

6

読書iOSのバージョン:

NSString* iOSVersion = [[UIDevice currentDevice] systemVersion]; 

読書のiPadモデル:

- (NSNumber *) totalDiskSpace 
{ 
    NSDictionary *fattributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil]; 
    return [fattributes objectForKey:NSFileSystemSize]; 
} 

- (NSNumber *) freeDiskSpace 
{ 
    NSDictionary *fattributes = [[NSFileManager defaultManager] attributesOfFileSystemForPath:NSHomeDirectory() error:nil]; 
    return [fattributes objectForKey:NSFileSystemFreeSize]; 
} 

BOOL isIPad2 = (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad && 
          [UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]); 
NSString* iPadModel = [[UIDevice currentDevice] model]; 
      if (isIPad2) 
       iPadModel = @"iPad2"; 

は無料/総容量ディスクを読みます

3

float totalSpace = 0.0f; 
float totalFreeSpace = 0.0f; 
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 floatValue]; 
totalFreeSpace = [freeFileSystemSizeInBytes floatValue]; 
NSLog(@"Memory Capacity of %f MiB with %f MiB Free memory available.", ((totalSpace/1024.0f)/1024.0f), ((totalFreeSpace/1024.0f)/1024.0f)); 
} else { 
NSLog(@"Error Obtaining System Memory Info: Domain = %@, Code = %@", [error domain], [error code]); 
} 

NSLog(@"%f",totalFreeSpace); 

は、デバイス名を見つけるには

[[UIDevice currentDevice] systemVersion]; 

は、ディスク内のスペースを見つけるには、IOSバージョンを確認する

NSLog(@"%@",[[UIDevice currentDevice] name]); 
関連する問題