本篇文章介绍关于 [UIDevice currentDevice] 的内容
1、系统 设备
NSLog(@"设备名称:%@", [UIDevice currentDevice].name);
NSLog(@"设备类型:%@", [UIDevice currentDevice].model);
NSLog(@"系统版本:%@", [UIDevice currentDevice].systemVersion);
NSLog(@"系统名称:%@", [UIDevice currentDevice].systemName);
NSLog(@"设备朝向:%lu", [UIDevice currentDevice].orientation); //枚举值
NSLog(@"UUID:%@", [UIDevice currentDevice].identifierForVendor.UUIDString);
NSLog(@"本地化模式:%@", [UIDevice currentDevice].localizedModel);
2、电池相关信息
//打开电视的监测设置
[UIDevice currentDevice].batteryMonitoringEnabled = YES;
//获取电池的状态
UIDeviceBatteryState state = [UIDevice currentDevice].batteryState
//电池状态
typedef NS_ENUM(NSInteger, UIDeviceBatteryState) {
UIDeviceBatteryStateUnknown, // 未知状态
UIDeviceBatteryStateUnplugged, // 未充电
UIDeviceBatteryStateCharging, // 充电中 未充满
UIDeviceBatteryStateFull, // 充电中 且已充满
}
//获取当前电池电量
NSLog(@"%f", [UIDevice currentDevice].batteryLevel);
3、判断当前连接的设备
//判断当前连接的设备
UIUserInterfaceIdiom interface = [UIDevice currentDevice].userInterfaceIdiom;
typedef NS_ENUM(NSInteger, UIUserInterfaceIdiom) {
UIUserInterfaceIdiomUnspecified = -1, //未知设备
UIUserInterfaceIdiomPhone // iPhone设备
UIUserInterfaceIdiomPad // iPad设备
UIUserInterfaceIdiomTV // Apple TV设备
UIUserInterfaceIdiomCarPlay // CarPlay设备
};
4、几个通知
// 屏幕方向变化通知
UIKIT_EXTERN NSString *const UIDeviceOrientationDidChangeNotification;
// 电池状态变化通知
UIKIT_EXTERN NSString *const UIDeviceBatteryStateDidChangeNotification NS_AVAILABLE_IOS(3_0);
// 电池电量变化通知
UIKIT_EXTERN NSString *const UIDeviceBatteryLevelDidChangeNotification NS_AVAILABLE_IOS(3_0);
// 接近状态变化通知
UIKIT_EXTERN NSString *const UIDeviceProximityStateDidChangeNotification NS_AVAILABLE_IOS(3_0);
注意:关于电池的两个通知, 必须设置 [UIDevice currentDevice].batteryMonitoringEnabled = YES!否则收不到通知
5、获取当前APP名称和版本号
//APP名称
NSString *appName = [[NSBundle mainBundle].infoDictionary objectForKey:@"CFBundleName"];
//APP版本号
NSString *appVersion = [[NSBundle mainBundle].infoDictionary objectForKey:@"CFBundleShortVersionString"];
//APP Build号
NSString *appBuild = [[NSBundle mainBundle].infoDictionary objectForKey:@"CFBundleVersion"];