react-native-ble-manager icon indicating copy to clipboard operation
react-native-ble-manager copied to clipboard

iOS Application in Test Flight/release build doesn't detect expected peripheral devices

Open t-roberts opened this issue 8 years ago • 14 comments

Version

Tell us which versions you are using:

  • react-native-ble-manager v6.2.4
  • react-native v0.48.4
  • iOS 9.1

Expected behaviour

When connected to a PC and running the app through xcode, my application can start, scan, detect, and connect to the expected peripheral devices

Actual behaviour

When i build the application and publish the app to test flight, the scan does not detect the expected peripheral devices. Am I missing something in the settings for apps in release mode instead of debug mode?

t-roberts avatar Jan 22 '18 20:01 t-roberts

Update: When running the application in release mode from xcode, this error occurs when calling scan, and does not occur in debug:

MobileApp[1220:827467] scan with timeout 3 2018-01-22 15:36:19.675216-0600 MobileApp[1220:827467] [CoreBluetooth] API MISUSE: <CBCentralManager: 0x1c4467e40> can only accept this command while in the powered on state 2018-01-22 15:36:19.675857-0600 MobileApp[1220:827492] [CoreBluetooth] XPC connection invalid 2018-01-22 15:36:22.677735-0600 MobileApp[1220:826354] Stop scan

Any idea what may be causing this?

t-roberts avatar Jan 22 '18 21:01 t-roberts

I think the bluetooth is off, you have to check before.

marcosinigaglia avatar Jan 23 '18 09:01 marcosinigaglia

Bluetooth is definitely on. Like i said, this exact code works when tethered to a machine in debug, but fails in release. I've also added the checkState call to make sure that the phone is reading that ble is ON.

t-roberts avatar Jan 23 '18 14:01 t-roberts

@t-roberts Interesting issue, maybe related to JS runtime. Can you further check whether app works correctly for both debugger on/off cases?

One fact often be ignored by RN developers is:

when in release (or non-debugging) mode, the JavaScriptCore in iOS will be the JS runtime, on the other hand for debugging, the V8 in Chrome will be the JS runtime.

BTW, this kind of issue is totally possible. Per my experience, iOS 9.x does in some case use array-like objects (ex. UINT8Array) rather than normal array, which will result in TypeError when you want to invoke array method such as forEach or map.

Hope that helps!

whitedogg13 avatar Jan 23 '18 14:01 whitedogg13

@whitedogg13 thanks for the reply. This code does work with both debugger on/off, in debug mode.

t-roberts avatar Jan 23 '18 14:01 t-roberts

I'm having the same issue:

2018-01-24 19:26:10.808302+0000 ****[10860:1204154] BleManager created 2018-01-24 19:26:11.022258+0000 ****[10860:1204211] BleManager initialized 2018-01-24 19:26:11.024337+0000 ****[10860:1204211] [CoreBluetooth] API MISUSE: <CBCentralManager: 0x1c0073f40> has no restore identifier but the delegate implements the centralManager:willRestoreState: method. Restoring will not be supported 2018-01-24 19:26:11.045930+0000 ****[10860:1204219] scan with timeout 3 2018-01-24 19:26:11.046050+0000 ****[10860:1204219] [CoreBluetooth] API MISUSE: <CBCentralManager: 0x1c0073f40> can only accept this command while in the powered on state 2018-01-24 19:26:14.064273+0000 ****[10860:1204154] Stop scan 2018-01-24 19:26:14.064754+0000 ****[10860:1204154] [CoreBluetooth] API MISUSE: <CBCentralManager: 0x1c0073f40> can only accept this command while in the powered on state

RN version: 0.52.1, react-native-ble-manager: 6.2.6

Shauneoo avatar Jan 24 '18 19:01 Shauneoo

Any updates or thoughts on this?

t-roberts avatar Jan 25 '18 14:01 t-roberts

Sorry, I'm not able to simulate your problm, try to use the restoreIdentifierKey option in the start method.

marcosinigaglia avatar Jan 25 '18 14:01 marcosinigaglia

So, including this in the startup did get the iOS device to scan and recognize devices. However, The .connect method does not return a promise or an error. I can see that i am connecting to the device, but theres no acknowledgement coming back from the connect method.

Should there be a specific value i'm using for the restoreIdentifierKey? I'm just tosisng in any old string for the time being.

t-roberts avatar Jan 25 '18 15:01 t-roberts

@t-roberts I'm still testing, but enabling Target > Background Modes > Uses Bluetooth LE accessories appears to have resolve my issue.

Shauneoo avatar Jan 25 '18 15:01 Shauneoo

got this to work by enabling LE Accessories and also providing a restoreIdentifierKey.

t-roberts avatar Jan 31 '18 16:01 t-roberts

@t-roberts Can you please provide more info. I have enabled LE Accessories and provided a restoreIdentifierKey, but I'm still getting the same error message API MISUSE

adnanba avatar May 30 '18 08:05 adnanba

For me the fix for the [CoreBluetooth] API MISUSE: <CBCentralManager: 0x...> can only accept this command while in the powered on state was to wait for a device to actually start Bluetooth by adding a delay after BleManager.start() and before calling BleManager.scan(...).

Probably using the BleManagerDidUpdateState event would be a better solution, but did not tried it yet.

Alexxzz avatar Jul 09 '18 14:07 Alexxzz

Below code working with me.

let data = dataByteArray.withUnsafeBufferPointer { bufferPointer -> Data in return Data(buffer: bufferPointer) } myPeripheral?.writeValue(data, for: firstWriteCharacteristic, type: .withResponse)

Remove the warning from the data object when creating data to be passed to the writeValue method.

sishpalR avatar Aug 01 '24 11:08 sishpalR