Skip to content

Commit

Permalink
Use IOBluetoothDevice.pairedDevices to get device by name
Browse files Browse the repository at this point in the history
IOBluetoothDevice.recentDevices return empty list in macOS Monterey and
later, use IOBluetoothDevice.pairedDevices instead, to make

  --info "BY NAME"
  --connect "BY NAME"
  --disconnect "BY NAME"
  ...

work again.

Fix toy#58 toy#62 toy#63
  • Loading branch information
azuwis committed Mar 24, 2024
1 parent 6477e3d commit b3bc943
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions blueutil.m
Original file line number Diff line number Diff line change
Expand Up @@ -277,14 +277,14 @@ bool parse_signed_long_arg(char *arg, long *number) {
exit(EXIT_FAILURE);
}
} else {
NSArray *recentDevices = [IOBluetoothDevice recentDevices:0];
NSArray *pairedDevices = [IOBluetoothDevice pairedDevices];

if (!recentDevices) {
eprintf("No recent devices to search for: %s\n", id);
if (!pairedDevices) {
eprintf("No paired devices to search for: %s\n", id);
exit(EXIT_FAILURE);
}

NSArray *byName = [recentDevices filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"name == %@", nsId]];
NSArray *byName = [pairedDevices filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"name == %@", nsId]];
if (byName.count > 0) {
device = byName.firstObject;
}
Expand Down

0 comments on commit b3bc943

Please sign in to comment.