2011-11-23 3 views
2

기기 이름, 유형, 디스크 공간 및 iOS 버전과 같은 일부 기기 정보를 읽으려면이 작업을 수행하십시오. 장치가 iPad, iPhone 또는 망막인지 알 수있는 몇 가지 방법이 있지만 장치에 대해 더 이상 알지 못하는 경우가 있습니다.코코아 터치 - 기기 정보 얻기

답변

6

읽기 아이폰 OS 버전 :

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

읽기 아이 패드 모델 :

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