Background time issue for Bluetooth LE app for Iphone 4s

故事扮演 提交于 2019-11-27 20:30:41

问题


I am using core-bluetooth framework for my app in Iphone-4s.
This is typically has to be a background app which can run as longer as possible.

Now it is only running for 40 min - 1 hour max.

I am hoping for at least 1 day or so.

For this "bluetooth-central" value is added in "Required background modes" key in .plist file.

It seems like my app is going to "suspend" mode, at the end. since when I open the app again (background to foreground state) it is sending the notification again, it means the bluetooth connection is still connected and BLE-device is still sending notification. If i press home button and app comes to background, it does NOT get notification again.

Can anybody tell me why my app live in background mode only for max 1 hour. It should continue run like normal music app in background for like forever.

Is Apple say anything specific about on which condition an background app (which is one of those continuous running background app falling with in the 5 categories) failing which it will go to suspend mode?

Referring "iPhoneAppProgrammingGuide", on "Communicating with a Bluetooth Accessory" section, I come to know that, for long running background task for Bluetooth LE application 2 implementations are necessory:

1) UIBackgroundModes key should be "bluetooth-central" in Info.plist file. 2) Any app that supports the background processing of Bluetooth data must be session-based.

So for my app, the FIRST implementation was incorporated, and with that application is able to run in background and do all the tasks for max 1 hour duration.

Now I need to implement 2nd implementation. i.e. session-based. Which will allow to get the events even if the app is in "suspend" state according to the documentation. I tried to find to create a suitable session specific to Bluetooth LE (Core Bluetooth framework) like the "EASession" present for Classic Bluetooth (External Accessory framework). But I did not find it.

Basically I am not sure which session class i need to use for BLE purpose. For audio/video, networking and internet, external accessory, there are individual session class available. There is none for Core Bluetooth framework.

Could anybody help me with, which session class is suitable for BLE.


回答1:


I think the problem is simple try to implement you info.plist like my screen:


And if you want you can add the function on AppDelegate.m under the didFinishLaunchingWithOptions to enable Bluetooth, AirPlay WiFi and more, this is only a example code, but i think can help you.
NSError *sessionError = nil;
[[AVAudioSession sharedInstance] setDelegate:self];
[[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayAndRecord error:&sessionError];
[[AVAudioSession sharedInstance] setActive:YES error:nil];

UInt32 sessionCategory = kAudioSessionCategory_MediaPlayback;
AudioSessionSetProperty(kAudioSessionProperty_AudioCategory, sizeof(sessionCategory), &sessionCategory);

UInt32 audioRouteOverride = kAudioSessionOverrideAudioRoute_Speaker;
AudioSessionSetProperty (kAudioSessionProperty_OverrideAudioRoute,sizeof (audioRouteOverride),&audioRouteOverride);

[[UIApplication sharedApplication] beginReceivingRemoteControlEvents];

Hope this can help you.



来源:https://stackoverflow.com/questions/10140260/background-time-issue-for-bluetooth-le-app-for-iphone-4s

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!