DeviceInfo-设备信息

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    //当前设备
    UIDevice *dev = [UIDevice currentDevice];

    //开启电池监控
    [[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];

    NSString *name = dev.name;
    NSString *model = dev.model;
    NSString *localizedModel = dev.localizedModel;
    NSString *systemName = dev.systemName;
    NSString *systemVersion = dev.systemVersion;
    NSString *uuid = [dev.identifierForVendor UUIDString];
    float batteryLevel = dev.batteryLevel;

    UIDeviceBatteryState bState = dev.batteryState;

    NSLog(@"name = %@\nmodel = %@\nlocalizeModel = %@\nsystemName = %@\nsystemVersion = %@\nuuid = %@", name, model, localizedModel, systemName, systemVersion, uuid);

    switch (bState) {
        case UIDeviceBatteryStateCharging:
            NSLog(@"充电中");
            break;
        case UIDeviceBatteryStateFull:
            NSLog(@"已充满");
            break;
        case UIDeviceBatteryStateUnplugged:
            NSLog(@"未充电");
            break;
        case UIDeviceBatteryStateUnknown:
            NSLog(@"状态未知");
            break;
    }

    NSLog(@"电量状态: %.2f%%", batteryLevel * 100);

    return YES;
}

你可能感兴趣的:(iOS)