- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
UIDevice *device = [UIDevice currentDevice];
device.batteryMonitoringEnabled = YES;
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(batteryChanged:) name:@"UIDeviceBatteryLevelDidChangeNotification" object:device];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(batteryChanged:) name:@"UIDeviceBatteryStateDidChangeNotification" object:device];
}
- (void)batteryChanged:(NSNotification *)notification
{
UIDevice *device = [UIDevice currentDevice];
NSLog(@"State: %i Charge: %f", device.batteryState, device.batteryLevel);
batteryLabel.text = [NSString stringWithFormat:@"State: %i Charge: %f", device.batteryState, device.batteryLevel];
}
UILabel从不更新。电源事件从未被解雇。iOS UILabel在断电时不会改变
我做错了什么?
我打算只支持的iOS 5.x和6
真的从来没有?你做了一个长期测试(几个小时)? – Felix 2012-07-05 17:06:12
我的电池电量为70%,假设每5%或1分钟触发一次。但即时通讯接近100%和UILabel从未改变 – 2012-07-05 17:15:22
我得到了通知中心工作,但UILabel没有更新。 – 2012-07-05 20:56:11