我执行此任务是为了读取一些设备信息,例如设备名称、类型、磁盘空间和 iOS 版本。我有一些方法可以知道该设备是 iPad、iPhone 还是视网膜,但我对进一步了解该设备一无所知。
最佳答案
阅读 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];
}
关于iphone - Cocoa touch——获取设备信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8242469/