Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
300 views
in Technique[技术] by (71.8m points)

ios - Background time issue for Bluetooth LE app for Iphone 4s

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

enter image description here
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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...