這是一個私人應用程序,它能夠在應用程序連接到用戶選擇的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小時左右,但由於操作系統在一段時間後強制休眠應用程序,因此此解決方案不可行 –