int state = 0; switch (battery_state) { case UIDeviceBatteryStateUnknown: state = 1; break; case UIDeviceBatteryStateCharging: // 充电中 state = 2; break; case UIDeviceBatteryStateUnplugged: // 放电中 state = 3; break; case UIDeviceBatteryStateFull: // 充满 state = 5; break; default: state = 0; break; } NSString *result = [NSString stringWithFormat:@"%.02f,%d,%d", battery_level*100, 100, state]; return result; }