【发布时间】:2013-08-08 10:55:39
【问题描述】:
整个问题都在标题中。
这是我所做的。
我测试它我将 iPhone 插入我的 Mac,而不是充电器我不知道这是否重要。
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{...
[UIDevice currentDevice].batteryMonitoringEnabled = YES;
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(batteryStateDidChange:)
name:UIDeviceBatteryStateDidChangeNotification object:nil];
...}
- (void)batteryStateDidChange:(NSNotification *)notification
{
[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
if ([[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateCharging ||
[[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateFull ){
[UIApplication sharedApplication].idleTimerDisabled = YES;
}
else if ([[UIDevice currentDevice] batteryState] == UIDeviceBatteryStateUnplugged) {
[UIApplication sharedApplication].idleTimerDisabled = NO;
}
}
我错过了什么?
【问题讨论】:
标签: iphone ios objective-c uidevice idle-timer