你好,所以我的应用程序中有一个功能,当用户的电池不足20%时,它会通知用户。
在我的附件中,我有这个(观察员)
- (void)applicationDidEnterBackground:(UIApplication *)application {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(batteryStatut) name:UIDeviceBatteryLevelDidChangeNotification object:nil];
[[UIDevice currentDevice] setBatteryMonitoringEnabled:YES];
}这个空白,nslog是更新的电池级别
-(void)batteryStatut{
float batteryLevel = [[UIDevice currentDevice] batteryLevel];
batteryLevel *= 100;
NSLog(@"Battery lvl changed: %f",batteryLevel);
}编辑:
使用应用程序在plist中添加UIBackgroundModes使用您的位置,它可以工作,但这不是最好的方法。
发布于 2015-02-13 08:28:14
如果你想让你的应用程序在后台工作,你必须声明你的应用程序支持背景任务。要做到这一点,您必须在.plist中为UIBackgroundModes注册一个值。
不幸的是,你必须有充分的理由使用背景任务。比如听音乐,位置,voip等等.因此,我想,如果没有脏东西,您就无法在用例中使用后台任务(比如使用位置来不杀死应用程序)。
有关更多详细信息,请查看医生
https://stackoverflow.com/questions/28495022
复制相似问题