可可触摸 - 获取设备信息

时间:2011-11-23 12:50:31

标签: iphone ios xcode cocoa-touch

我执行此任务来读取某些设备信息,例如设备名称,类型,磁盘空间和iOS版本。我有一些方法可以知道这个设备是iPad,iPhone还是视网膜,但是我对进一步了解这个设备一无所知。

2 个答案:

答案 0 :(得分: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];
}

答案 1 :(得分: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]);
相关问题