Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(iOS) startScanning() not working #267

Open
raphcibo1 opened this issue Feb 27, 2023 · 2 comments
Open

(iOS) startScanning() not working #267

raphcibo1 opened this issue Feb 27, 2023 · 2 comments

Comments

@raphcibo1
Copy link

Hi,

I'm facing an issue that I can't explain when trying to get info on a BLE device. StartScanning() seems to not doing anything only on iOS. On Android, everything works as expected.

Here's my method and on iOS, nothing comes from onDiscovered :

bleRoutine(){
        try{
            let self = this;
            this.bluetooth.startScanning({
                //filters: [{serviceUUID:'00001000-0000-1000-8000-00805f9b34fb'}],
                seconds: 3,
                avoidDuplicates: true,
                onDiscovered: function (peripheral) {
                    if(peripheral.name == "T201"){
                        let dataView = new DataView(peripheral.advertismentData.manufacturerData);
                    }
                }
            }).then(function() {
                //console.log("scanning complete");
                //if(!self.bleStop) self.bleRoutine();
                // self.connectToDevice();
                //self.bleConnections();
            }, function (err) {
                //console.log("error while scanning: " + err);
            });
        }catch(e){
            console.log("ble catch");
            console.log(e);
        }
    }

Here's what I added in my Info.plist :

<key>NSBluetoothAlwaysUsageDescription</key>
<string>Our app uses bluetooth to find, connect and transfer data between different devices</string>
<key>NSBluetoothPeripheralUsageDescription</key>  
<string> Our app uses bluetooth to find, connect and transfer data between different devices</string>
<key>NSLocationWhenInUseUsageDescription</key>  
<string> Our app uses location</string>

I also checked Uses Bluetooth LE accessory in Background Modes in Xcode.

I also have a bluetooth message when I start the app as expected. I am in native script version 8.1.4 and "@nativescript-community/ble": "^3.1.15"

Am I missing something ? (maybe something obvious that doesn't ring a bell in my head)

@farfromrefug
Copy link
Member

@raphcibo1 did you ask for location permission at runtime? it is needed to be able to scan
also did you add a simple console.log in onDiscovered to see if it sees something?

@NathanWalker
Copy link
Member

NathanWalker commented May 7, 2023

Another thing to check here is the name adding spaces from the device, for example this conditional:

if(peripheral.name == "T201"){

may be causing you to think no devices are received - it's common the bluetooth device names may have leading or trailing spaces, eg: "T201 "

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants