这是一个私人应用程序,它能够在应用程序连接到用户选择的BT时执行一些操作。 我们使用bluetoothmanager.framework
通过https://github.com/michaeldorner/BeeTee不幸的是,它似乎不能唤醒应用程序,如果它在后台。 可能吗?我们很高兴能有任何线索如何处理。应用程序永远在活动背景 - 私人应用程序
所以我们需要找到一种方法来保持应用程序在后台保持活跃状态,而用户在没有大量电池消耗的情况下不会杀死它。
目前我们使用这项工作,保持应用程序。活跃于2 & 4小时以内。 (不够明显,但与这一个应用程序消耗无:在2小时内〜1%)
背景模式:
- VOIP
- 位置更新
- 背景取
- 音频播放
使用的代码:
- (void)applicationDidEnterBackground:(UIApplication *)application {
if([[NSUserDefaults standardUserDefaults]objectForKey:@"account"]){
_background_task = [application beginBackgroundTaskWithExpirationHandler:^ {
NSLog(@"cleanup code for end of background allowed running time");
[application endBackgroundTask: _background_task];
_background_task = UIBackgroundTaskInvalid;
}];
// run background loop in a separate process
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSLog(@"start of background loop");
while (TRUE)
{
NSTimeInterval remaining = [[UIApplication sharedApplication] backgroundTimeRemaining];
// background audio resets remaining time
if (remaining < 60) {
[self playSpeech:@"up" andVolume:0.0];
}
[NSThread sleepForTimeInterval:1]; //wait for 1 sec
}
NSLog(@"end of background loop");
[application endBackgroundTask: _background_task];
_background_task = UIBackgroundTaskInvalid;
});
[[Detector singleton] startDetection];
}
}
如何保持在后台活着应用程序,而不破坏用户的电池任何线索?
*使应用程序保持活动状态而不损坏用户电池*?这是矛盾的。如果后台任务不做任何事情,则不会耗费电池寿命。但是,如果您使用GPS /蓝牙,它必须不断消耗电池(虽然BLE会减少电池的使用) – Raptor
我不被允许具体,但目前有一些条件可以在连接到“某些东西”之后BT。所以目前正常使用的工作约为电池消耗的1%/ 2小时左右,但由于操作系统在一段时间后强制休眠应用程序,因此此解决方案不可行 –