iOS Question [PENDING SOLVED] BLE Background

Jmu5667

Well-Known Member
Licensed User
Longtime User
Hello

Has anyone acheived a BLE connection to an iTag device and kept the connetion live in the background on an iPhone. I have an app(SOS app) that stays running in the background. It can get GPS coords, do beacon scanning and check the angle(mandown) of the device(getGravity) all in the background no problems.

When I connect to an iTag device, used to active an SOS alert, I get data available (3 key press to trigger the alert), and can set off the SOS. The app is killed shortly afterwards, within 1 minute.

The app connects to backend B4J servers for transmitting alert packets. This is a commerical application and and the same apps is already in use on Android with thousands of users.

' // application header
B4X:
   #Entitlement: <key>com.apple.developer.networking.wifi-info</key><true/>
   
    #PlistExtra: <key>NSLocationAlwaysAndWhenInUseUsageDescription</key><string>Track your location in the background to assist in SOS emergency alerting.</string>
    #PlistExtra: <key>NSLocationAlwaysUsageDescription</key><string>Track your location in the background to assist in SOS emergency alerting.</string>
    #PlistExtra: <key>NSLocationUsageDescription</key><string>Track your location in the background to assist in SOS emergency alerting.</string>
    #PlistExtra: <key>NSLocationWhenInUseUsageDescription</key><string>Track your location in the background to assist in SOS emergency alerting.</string>
    #PlistExtra: <key>NSBluetoothAlwaysUsageDescription</key><string>Bluetooth used scan for indoor Beacons to assist indoor positioning</string>
   
    ' // set permitted background modes   
    #PlistExtra: <key>UIBackgroundModes</key>
    #PlistExtra: <array>
    #PlistExtra:     <string>location</string>
    #PlistExtra:     <string>bluetooth-central</string>
    #PlistExtra:     <string>bluetooth-peripheral</string>   
    #PlistExtra:     <string>audio</string>
    #PlistExtra: </array>

    ' // Status bar style   
    #PlistExtra: <key>UIStatusBarStyle</key>
    #PlistExtra: <string>UIStatusBarStyleLightContent</string>
    #PlistExtra: <key>UIViewControllerBasedStatusBarAppearance</key>
    #PlistExtra: <false/>

    #DeviceCapabilities: location-services, bluetooth-le


Any ideas/views appreciated.

Regards

John.
 
Last edited:

Jmu5667

Well-Known Member
Licensed User
Longtime User
Are you sure that the connection is still valid when the app quits?

Yes the connection is still open/valid, when the app is killed the connection is severed, the iTag will then beep for 30 seconds. This is how I know that the app has been killed. I will implement then StartBackgroundTask method in any class that sends data to the b4J server to see if that sorts out the problem.
 
Upvote 0

Jmu5667

Well-Known Member
Licensed User
Longtime User
Update:

When an Alert is activated in the app a new page is displayed to the user. The user has 2 option's, False and Close. Selecting either option will send a message to the B4J server and the Alert is closed. About 50 seconds later the app is killed.

The Fix:
Instead of showing a new page, I display a panel on main page with the same options, False and Close. The message is sent to the B4J server and the Alert is closed. The app is not killed but stays alive.

Is there something special about Main that if methods are called from another page it seems to break the apps background permissions. This was the final solution we came up with.

Regards

John.
 
Upvote 0
Top