我执行这个任务是为了读取一些设备信息,如设备名称,类型,磁盘空间和iOS版本。我有办法知道这个设备是iPad、iPhone还是retina,但我对这个设备一无所知。
阅读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];
}
查找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]);