Route audio through bluetooth ios - ios

I need some help from you ....
I have an app for VoIP calling and i need to route audio of call through bluetooth even in background (in case someone press home button while call is in progress ).. Do i need to set anything in info.plist file in background modes ??
This is what i have been set for background modes to use bluetooth and apple rejected app with given reason below :
2.16 Details
Your app declares support for bluetooth-central, and bluetooth-peripheral, in the UIBackgroundModes key in your Info.plist, but does not provide Bluetooth Low Energy functionality. The Bluetooth Background modes are for applications that communicate to other devices using Bluetooth Low Energy and the Core Bluetooth framework.
Next Steps
Please revise your app to add support for Bluetooth Low Energy communication through Core Bluetooth in your application or remove the bluetooth- values from the UIBackgroundModes key.
Please help me out ....
Thanks in Advance !!!

This is because you are not using core Bluetooth functions in your app.Just check "Audio and Airplay" and "Voice over IP" check boxes under Background Modes and resubmit the app.

Related

continuous run app in background. iOS Swift

in my app, I am connecting my app to BLE device. and I am fetching BLE data from BLE device at every 1 second. it working fine when I do this in the foreground.but I want to do same in the background even when the app will be in the background I need to fetch data continuously from BLE device. right now its stoped automatically after 2 minutes.
Please let me know if it's feasible or not?
Thanks in advance
You need to enable Background Mode in your project settings under capabilities tab. Under background modes you will find a few modes that satisfy various purposes of running an app in background. From these you have to enable the ones that you think are suitable according to the task that your app will perform in background. I think, you should enable external accessory communication and background fetch.
Also you need to implement a background task when your app enters background. This is done in app delegate's didEnterBackground method.
Apple documentation
Apps that work with Bluetooth peripherals can ask to be woken up if the peripheral delivers an update when the app is suspended. This support is important for Bluetooth-LE accessories that deliver data at regular intervals, such as a Bluetooth heart rate belt. You enable support for using bluetooth accessories from the Background modes section of the Capabilities tab in your Xcode project. (You can also enable this support by including the UIBackgroundModes key with the bluetooth-central value in your app’s Info.plist file.) When you enable this mode, the Core Bluetooth framework keeps open any active sessions for the corresponding peripheral. In addition, new data arriving from the peripheral causes the system to wake up the app so that it can process the data. The system also wakes up the app to process accessory connection and disconnection notifications.
In iOS 6, an app can also operate in peripheral mode with Bluetooth accessories. To act as a Bluetooth accessory, you must enable support for that mode from the Background modes section of the Capabilities tab in your Xcode project. (You can also enable this support by including the UIBackgroundModes key with the bluetooth-peripheral value in your app’s Info.plist file.) Enabling this mode lets the Core Bluetooth framework wake the app up briefly in the background so that it can handle accessory-related requests. Apps woken up for these events should process them and return as quickly as possible so that the app can be suspended again.
Any app that supports the background processing of Bluetooth data must be session-based and follow a few basic guidelines:
Apps must provide an interface that allows the user to start and stop the delivery of Bluetooth events. That interface should then open or close the session as appropriate.
Upon being woken up, the app has around 10 seconds to process the data. Ideally, it should process the data as fast as possible and allow itself to be suspended again. However, if more time is needed, the app can use the beginBackgroundTaskWithExpirationHandler: method to request additional time; it should do so only when absolutely necessary, though.

How to share data between apps while in background?

I'm afraid I already know the answer of my own question, but I decided to ask anyway before losing my hopes.
I have the following use case: an app writes some bytes in a "shared" resource (let's say on a file) and another app reads the data and sends them to an external device via BLE while in background. Unfortunately, I know that concepts like shared resource and background are bounded in iOS. What I tried so far is:
Using App Group to share data between two apps
This is working fine even in background, but both the apps need to be produced by the same developer team (i.e. Team ID must be the same). This is a problem because one app is not produced by my developer team.
Copying data in the pasteboard
This is not working when app is in background. Data will always be nil and will update only when the app becomes active again.
...and of course there are...
Background limitations
Even though I go for the App Group solution, the only way I can manage to read data and send to the BLE device in background is by starting a background task. This obviously is a caveat: the task has an expiration time (from tests I performed it keeps going for about 3 minutes before being suspended by the OS). I don't need to run a long-time task, but I cannot assure it can be performed completely by 3 minutes or so.
Here's the question: Is there some other solution for this use case or should I finally give up?
If you are using CoreBluetooth to send files to your Bluetooth device, you can try adding bluetooth-central as UIBackgroundMode key in Info.plist of your app.
Apple has mentioned this in its programming guide:
Communicating with a Bluetooth Accessory Apps that work with Bluetooth
peripherals can ask to be woken up if the peripheral delivers an
update when the app is suspended. This support is important for
Bluetooth-LE accessories that deliver data at regular intervals, such
as a Bluetooth heart rate belt. You enable support for using bluetooth
accessories from the Background modes section of the Capabilities tab
in your Xcode project. (You can also enable this support by including
the UIBackgroundModes key with the bluetooth-central value in your
app’s Info.plist file.) When you enable this mode, the Core Bluetooth
framework keeps open any active sessions for the corresponding
peripheral. In addition, new data arriving from the peripheral causes
the system to wake up the app so that it can process the data. The
system also wakes up the app to process accessory connection and
disconnection notifications.
In iOS 6, an app can also operate in peripheral mode with Bluetooth
accessories. To act as a Bluetooth accessory, you must enable support
for that mode from the Background modes section of the Capabilities
tab in your Xcode project. (You can also enable this support by
including the UIBackgroundModes key with the bluetooth-peripheral
value in your app’s Info.plist file.) Enabling this mode lets the Core
Bluetooth framework wake the app up briefly in the background so that
it can handle accessory-related requests. Apps woken up for these
events should process them and return as quickly as possible so that
the app can be suspended again.

UIBackgroundModes external-accessory

I have added "App communicates with an accessory” under the Key “Required background modes” in my apps info-plist so that when the app is killed in any way iOS will prompt the user to restart the background syncing for any connected BLE devices.
I have read lots of documentation and seen lots of comments however nothing concert I have only had one other person tell me if I use this our app it will not be accepted into the app store.
The external-accessory background mode is for MFi accessories, not BLE accessories. There are separate Core Bluetooth background mode entitlements for BLE (bluetooth-central and bluetooth-peripheral).
If you declare the MFi accessory background mode but your app does not connect to external MFi accessories then you can expect your app to be rejected.
This is covered by clause 2.16 of the App Store Review Guidelines
2.16 Multitasking Apps may only use background services for their intended purposes: VoIP, audio playback, location, task completion, local notifications, etc.

Airplay and Use of Bluetooth LE accessories

My app is using airplay. Do i need to select "Uses Bluetooth LE accessories" option in info.plist.
I submitted the app with checking this option and my app got rejected. Apple said that "Your app declares support for bluetooth-central in the UIBackgroundModes key in your Info.plist, but does not provide Bluetooth Low Energy functionality. The Bluetooth Background modes are for applications that communicate to other devices using Bluetooth Low Energy and the Core Bluetooth framework."
You should just check the airplay not the other options . Like in picture you should only select first one unless you are also using LE and implementing corebluetooth.

Is there work background services for Bluetooth low energy (BLE) on iOS?

I would like do coding in ios with Bluetooth low energy(BLE). i wanting to show notification of new BLE device while app background. is possible do it? I bought BLE Device from sensor tag site.
Yes, it is possible both in central and peripheral mode. You should declare the necessary permissions in your Info.plist and then you can search for one specific service in the background with the standard method scanForPeripheralsWithServices:options: of CBCentralManager Start with reading the docs of Apple.

Resources