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

🐛 IOS 17.7 and IOS 18.0.1 not able to read ble device characteristics.

Open sumitsharma7667 opened this issue 1 year ago • 7 comments

Prerequisites

  • [X] I checked the documentation and FAQ without finding a solution
  • [X] I checked to make sure that this issue has not already been filed

Expected Behavior

It should show device characterstics

Current Behavior

It not showing device characterstics

Library version

3.2.1

Device

iphone 14

Environment info

System:
    OS: macOS 14.6.1
    CPU: (10) arm64 Apple M1 Pro
    Memory: 89.20 MB / 16.00 GB
    Shell: 5.9 - /bin/zsh
  Binaries:
    Node: 20.11.0 - ~/.nvm/versions/node/v20.11.0/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v20.11.0/bin/yarn
    npm: 10.2.4 - ~/.nvm/versions/node/v20.11.0/bin/npm
    Watchman: 2024.10.21.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.15.2 - /opt/homebrew/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 23.5, iOS 17.5, macOS 14.5, tvOS 17.5, visionOS 1.2, watchOS 10.5
 IDEs:
    Android Studio: 2024.2 AI-242.23339.11.2421.12483815
    Xcode: 15.4/15F31d - /usr/bin/xcodebuild
  Languages:
    Java: 17.0.13 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 18.2.0 => 18.2.0 
    react-native: 0.71.11 => 0.71.11 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

Steps to reproduce

1 - start device scan. 2 - read characteristics. 3- decode characteristics

Formatted code sample or link to a repository

async function scanBlePlxDevices(UUID: string) {
    setUuid(UUID);

    return new Promise(async (resolve, reject) => {
        let device: Device | null = null;

        // Start scanning for devices
        const scanSubscription = await bleManager.startDeviceScan(null, null, async (error, bleDevice) => {
            if (error) {
                await bleManager.stopDeviceScan();
                return reject(new Error("Device scan failed"));
            }

            // Check if a device with the desired prefix is found
            if (bleDevice?.name) {
                bleManager.stopDeviceScan();
                device = bleDevice;

                try {
                    // Connect to the device and discover services/characteristics
                    await device.connect();
                    await device.discoverAllServicesAndCharacteristics();
                    const services = await device.services();
                    const characteristics = await services[0].characteristics();

                    // Decode and display characteristics
                    const values = await Promise.all(characteristics.map(async (c) => {
                        try {
                            return c.value ? base64.decode(c.value).toString('utf8') : '';
                        } catch (err) {
                            console.warn(`Error decoding characteristic: ${err.message}`);
                            return null;
                        }
                    }));

                    setCaps(values.filter(Boolean)); // Store non-empty values
                    resolve(device);
                } catch (err) {
                    return reject(new Error("Failed to connect or retrieve characteristics"));
                } finally {
                    await bleManager.destroy();
                }
            }
        });

        // Stop scanning if no device is found within the timeout
        setTimeout(async () => {
            await bleManager.stopDeviceScan();
            if (!device) reject(new Error("No device found within timeout period"));
        }, 10000); // Adjust timeout duration as needed
    });
}

Relevant log output

Additional information

IMG_2906 IMG_2907 IMG_2926 I am trying to decode from base64

sumitsharma7667 avatar Nov 12 '24 04:11 sumitsharma7667

i'm facing same issue

RohitDeshwal avatar Nov 12 '24 05:11 RohitDeshwal

Any fix yet?

GBR-422777 avatar Nov 17 '24 22:11 GBR-422777

Thanks for reporting this! We’ve added it to our backlog and will review it soon.

aliberski avatar Jan 18 '25 20:01 aliberski

Confirming same behaviour on iOS 17.6.1

dahlmo avatar Jan 23 '25 22:01 dahlmo

Facing similar issue trying to run device.monitorCharacteristicForService() to monitor notification from devices, works properly with android but not with iOS (version 18.1)

hasnatfahim12 avatar Jan 28 '25 15:01 hasnatfahim12

Any fix yet?

hasnatfahim12 avatar Mar 12 '25 11:03 hasnatfahim12

@hasnatfahim12 Maybe you can try v3.5.0? I see there's been some recent changes to the iOS characteristics part of the code, but it doesn't seem to be tracked so not completely sure if this will fix it.

dahlmo avatar Mar 14 '25 07:03 dahlmo