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

NSInvalidArgumentException thrown in findPeripheralByUUID #1014

Closed
kenguest opened this issue Jun 4, 2024 · 7 comments · Fixed by #1021
Closed

NSInvalidArgumentException thrown in findPeripheralByUUID #1014

kenguest opened this issue Jun 4, 2024 · 7 comments · Fixed by #1021
Assignees
Milestone

Comments

@kenguest
Copy link

kenguest commented Jun 4, 2024

Hi, I've gotten a few reports via Sentry.io of NSInvalidArgumentException being thrown in findPeripheralByUUID under iOS.

Exception message is: "[__NSCFBoolean isEqualToString:]: unrecognized selector sent to instance 0x20e8e3ce8"

  • (CBPeripheral*)findPeripheralByUUID:(NSString*)uuid {
    CBPeripheral *peripheral = nil;

    for (CBPeripheral *p in peripherals) {

      NSString* other = p.identifier.UUIDString;
    
      if ([uuid isEqualToString:other]) {
          peripheral = p;
          break;
      }
    

    }
    return peripheral;
    }

Stacktraces are showing this occurring when findPeripheralByUUID is called from isConnected.

I'm unfamiliar with Objective C so I'm not in a position to provide a patch for fixing this.

@peitschie
Copy link
Collaborator

Thanks @kenguest

Do you have an example of what the string your searching for is (i.e,. the UUID you're supplying to the code there)?

I agree the plugin shouldn't be crashing for this!

@peitschie peitschie added this to the next milestone Jun 7, 2024
@kenguest
Copy link
Author

we're passing the bluetooth mac address, one such uuid is 12:A1:8B:EC:86:CC

@peitschie
Copy link
Collaborator

@kenguest that looks to me like a MAC address rather than a uuid.
A uuid is usually of a form more like: b111d2f9-2cb5-4541-9119-015b8836d0fb

On Android, the ID reported by the phone is often the MAC address found in the broadcast packet. On iOS however, this is normally a guid, and is not predictable between installs.

Are you locating your device via a scan before trying to connect? Or are you wanting to connect to a device with a known MAC address on iOS?

@kenguest
Copy link
Author

we first detect devices to connect to by checking bluetooth advert packets, then determine if the packets are coming from one of our devices. If so we get the mac address (which we intentionally embed in the advert packets) and if appropriate (eg. wanting to read from a specific characteristic) we attempt to connect via that mac address.

Apart from the rare occurrence of this issue happening everything works fine.

@peitschie
Copy link
Collaborator

Hrm... this is definitely a mystery, as iOS has no way to map the MAC address back to the UUID it demands for connection.

I'll have a look tomorrow at making this plugin more clearly error out rather than crashing when handed a non-UUID identifier.

But... I don't see how this fixes your case here specifically, as I don't really understand how your approach of calling ble.connect(macAddress) ever worked on iOS 🙂

@peitschie
Copy link
Collaborator

I've pushed a fix for this in cordova-plugin-ble-central@1.7.5-alpha.0

@kenguest are you able to see if this addresses the issue you're seeing here?

@kenguest
Copy link
Author

thanks - I'll see if it does.
To revert back to your question, you're absolutely correct - ble.connect() under iOS is taking values such as this guid 9DA4BDEB-3AB1-2066-8C99-0F8991036CED to denote what device to connect to whereas Android uses mac addresses.

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

Successfully merging a pull request may close this issue.

2 participants