Can I communicate with a slave BLE even if app is not running? - ios

I am developing an iOS application that communicates with a slave BLE device. I know iOS will allow my app to run in background to communicate with BLE. What my doubt is that is there any way to turn on my app if there is any BLE near by? I mean even if my app is not running can I communicate with BLE? Like location service works,i.e., if the app registered for a significant location change alert then app will get automatically turned on when there is a significant location change even if app is not running.
I have searched a lot, but couldn't find any helpful documentation. Any help is greatly appreciated..

There are a few things here and I think you have to be careful with terminology. Let's first clarify "Not running". The app has 5 modes it can be in:
Foreground: the app is "live" and on the screen
Background - unlocked: the app is "live" but not on the screen. There is either another app on the screen (front) or possibly the user is on the home screen, browsing his/her apps, etc..
Background - locked: self explanatory
Terminated by user - still on device: The user has double clicked the home button and flicked your app up (iOS7) to close it.
Terminated by system - still on device: The app has been terminated by OS because of memory pressure (other apps needed the memory space).
Obviously, if the user has deleted the app from the device then there is nothing to discuss.
In option 4, the app is still on the device but will not relaunch any of its background services (BLE, location updates, etc..) until the user relaunches the app. This is new iOS7 behavior. If the user terminated the app then he/she does not want it running.
In option 5, because the user has not terminated the app; the OS will relaunch the app background services as it receives callbacks.
In order for an app to run in the background, it requires that you add the appropriate background modes to its plist or simply click on project (top left) and go to "Capabilities" and enable "Background modes" and the appropriate background mode. In your case: "Uses Bluetooth LE Accessories".
Now you seem to be looking for "Scanning" versus connecting and exchanging data and in my experience, scanning will only work in scenarios 1 and 2 and 5. Not 3. I have tried many times to get scanning to happen while phone is locked with no luck.
Now the way, fitbit etc... work in the background is that the app, scans, discovers services and characteristics and "setup updates" between the phone and accessory while the app is in the foreground. Once this setup is done, the "value of interest" updates (heart beat, etc..) can happen between the BLE acessory and the iOS device, in the background (locked and unlocked).
Hope this helps.

Related

How Do i relaunch my iOS app from Kill state for long task?

First i will explain what i want to achieve.
I have a BLE lock. i want that my application will wake up from kill state and start scanning BLE device. Once the BLE device found it will connect with my phone and get unlock.
All this is working in background mode and i tested this many times. but i also want this to be work when app is in kill state.
I tried several things. First I tried Geofencing but in case of geofencing app wake up for less time i'm not properly scan the BLE device. When didEnterRegion region: called i sent the local notification and it was working fine. So after that i tried to scan BLE Devices when didEnterRegion region: and also get the notification that scan is started but i think after some time app remove from the background automatically and could not relaunch. So that's why i'm failed to discovered any BLE device.
I also read apple document for Core BlueTooth:
https://developer.apple.com/library/archive/documentation/NetworkingInternetWeb/Conceptual/CoreBluetooth_concepts/CoreBluetoothBackgroundProcessingForIOSApps/PerformingTasksWhileYourAppIsInTheBackground.html
There is mention that how to perform long task like open and close door lock but isn't help me.
Please guide me how to do this when app is in kill state.
Thanks for the help :)
UPDATE:
What i mean from kill state is suspended/ terminated/removed from background. I just want that once user get enter into the region of geofence then app launch in background and scanning for the BLE device started. so after that i want app will stay into the background until door get unlock.
As Paulw11 mentioned, there's no way to relaunch an app in the background once it is terminated/killed by the user. Apple have done this deliberately for security and functionality reasons: if a user deliberately kills an app because it is buggy/faulty, the app should not be able to relaunch itself.
More information can be found here:-
Core Bluetooth Background Processing for iOS Apps
BLE device keep connect with iPhone when application terminate
I hope this helps.
did u try SLC. It wakes up the app after a kill. Then u can run a long running background task for BLE activity.

iOS background service using BLE after reboot

I'm new to mobile development, before eventually deciding where to develop (android/ iOS) a specific application I have a question (I'd prefer using an iPhone):
So the background is that I have a BLE device frequently sending data to the phone and let the phone app sync the data to the cloud. Now, it is really important that if for some reason the phone has to restart, it will automatically proceed receiving the BLE data.
Is it possible at all in iOS to start a background process (handling BLE packets) after reboot automatically. Thus e.g. when the respective BLE device pairs to the phone after a reboot, that the background process starts automatically, without the user having to start the app manually?
Doing some research I came up with mixed results regarding this scenario and would be grateful if someone with iOS experience could clarify.
(BTW: It does not have to be an Apple App Store Application)
A Few days ago I was working on BLE devices Beacons we supposed to make mobile application and start monitoring these beacons and send date monitoring to API.
This works fine in background, even the user was not running the application in foreground or reboot his iPhone.
All we should do is put the monitoring code at the appDelegate of the application to work in the background.

Push Notification App Running in Background When BLE is Connected

I worked on an Application which is Worked on BLE. i want push a notification ( App Running in Background When BLE is Connected) if any changes in Hardware. I Read Document
Even if your app supports one or both of the Core Bluetooth background execution modes, it can’t run forever. At some point, the system may need to terminate your app to free up memory for the current foreground app—causing any active or pending connections to be lost, for instance.
can i achieve my goal even my app in Background . If It is Possible Suggest me how to Achieve this . Thanks In Advance.
You may keep app in background by means of:
1.Audiosession(use this to play silent sound)
2.Location
3.VoIP
Any method can keep App in background and avoid App from being killed by system.
BLE Runs in the background, you need to specify that your app uses BLE Accessories or your app acts as a LE Accessory in the Background modes in app capabilities.
I've tried firing local notifications, while the application is in the background. BLE even works if the app is killed by the system, when the OS receives some communication from your peripheral or central, iOS wakes your app up and executes the desired function, before putting your app back to sleep.

Launching iOS BLE Central application on iPhone reboot

I am planning to develop an iOS application using CoreBluetooth framework which monitors a pedometer peripheral continuously and counts the footsteps.
I know that if backgroud execution mode is set to BLE Central, the application will continue to receive BLE events even in the background.
Apple documentation states that in case the app gets terminated due to low memory, the system can keep track of BLE events for a particular Central Manager if state preservation and restoration is adopted.
Assume I have an iOS application that operates in Central mode. The app is subscribed to receive notification from a Pedometer when ever the footstep characteristic changes.
I have adopted the following in my app.
BLE Central background mode
BLE State preservation/restoration for Central Manager
I start my app, Scan, Pair and Connect to the pedometer and the app starts receiving footsteps.
My Questions:
Now if the iPhone reboots, Will I continue to receive BLE events so that my app will be launched in the background without the user having to manually launch the application again and connect to the pedometer?
If the app is terminated by the user explicitly using the multitasking gesture, Will the app be able to receive BLE events without the user having to manually launch the application again and connect to the pedometer?
Is there a way to launch my application on iOS boot up?
Now if the iPhone reboots, Will I continue to receive BLE events so that my app will be launched in the background without the user having to manually launch the application again and connect to the pedometer?
Your app won't receive BLE events because all apps are started in the terminated state after a reboot (despite remaining in the app switcher). The user will have to manually launch your app at least once after reboot in order for it to use BLE.
If the app is terminated by the user explicitly using the multitasking gesture, Will the app be able to receive BLE events without the user having to manually launch the application again and connect to the pedometer?
Same as above, the app has entered the terminated state, so it won't be able to communicate using BLE until it is explicitly launched again.
Is there a way to launch my application on iOS boot up?
iOS doesn't provide any way to launch your application on boot.
The one exception to all of this that I can find is iBeacons. If your app registers to receive updates for a specific iBeacon, iOS will launch your app when it finds it (even after a reboot or if the user explicitly kills it from the switcher). When you get the iBeacon callback you can start all your BLE logic and it will then run in the background per usual. Of course this means you need to advertise as an iBeacon on your pedometer, which may or may not be feasible.
Bear in mind the detection of the iBeacon is pretty finicky, especially after a reboot. You have little guarantee as to how fast or even if you will be delivered the iBeacon callback to start your app. But it's something.
Source

Geo Notification on app that is off

Geo Fencing is praised by many, yet I could not easily find an answer to the following.
iOS and/or Android, does an inactive app send you notifications if you are close by?
My question is probably more like: is there an underlying system that knows your app needs to check for your location against the in-app locations and does so despite the app not being active.
Forget the settings where you can switch off geolocation for particular apps, let's assume that is switched on.
But let's assume I just switched my iphone on, no app is running yet. So I am carrying that sleeping phone in my pocket. Would I receive location notifications?
I am currently testing this with Highlight, but maybe someone knows the code/tech side to this answer.
Varies by OS.
On Android, apps can run as a service that are automatically started when the phone boots up. In this case, the user does not need to start the app. So, on Android, yes you would receive location notifications in sleep mode. See http://developer.android.com/guide/components/services.html or https://stackoverflow.com/questions/9866970/tutorial-for-android-services for more info on Android Services.
On Apple, I'm not so sure about running apps as a service like Android. However, I believe there are events that apps in the background can register for. So again, the app (once started) would receive notifications in sleep mode.

Resources