2011-11-23 90 views
2

我會執行此任務來讀取設備信息,如設備名稱,類型,磁盤空間和iOS版本。我有一些方法可以知道該設備是iPad,iPhone還是視網膜,但我知道該設備還有什麼進展。Cocoa touch - 獲取設備信息

回答

6

讀的iOS版本:

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

閱讀的iPad型號:

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

閱讀遊離/總磁盤空間:

- (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]; 
} 
3

要找到IOS版本

[[UIDevice currentDevice] systemVersion]; 

要查找的磁盤空間

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); 

查找設備名稱

NSLog(@"%@",[[UIDevice currentDevice] name]);