UIDevice - 获取iPhone系统信息

本篇文章介绍关于 [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"];
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值