From 17f834edef8e026258c211a6db80b837925797ff Mon Sep 17 00:00:00 2001 From: Rohit Sangwan Date: Tue, 7 Jan 2025 08:55:32 +0000 Subject: [PATCH] Improve example app for system connected devices (#123) * Improve example app for system connected devices * Add print when no filter is set for system devices --------- Co-authored-by: Foti Dim --- darwin/Classes/UniversalBlePlugin.swift | 2 ++ example/lib/home/home.dart | 13 +++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/darwin/Classes/UniversalBlePlugin.swift b/darwin/Classes/UniversalBlePlugin.swift index 178b38b..f23e7b2 100644 --- a/darwin/Classes/UniversalBlePlugin.swift +++ b/darwin/Classes/UniversalBlePlugin.swift @@ -293,6 +293,8 @@ private class BleCentralDarwin: NSObject, UniversalBlePlatformChannel, CBCentral func getSystemDevices(withServices: [String], completion: @escaping (Result<[UniversalBleScanResult], Error>) -> Void) { var servicesFilter = withServices if servicesFilter.isEmpty { + print("No services filter was set for getting system connected devices. Using default services...") + // Add several generic services servicesFilter = ["1800", "1801", "180A", "180D", "1810", "181B", "1808", "181D", "1816", "1814", "181A", "1802", "1803", "1804", "1815", "1805", "1807", "1806", "1848", "185E", "180F", "1812", "180E", "1813"] } diff --git a/example/lib/home/home.dart b/example/lib/home/home.dart index a142575..502df92 100644 --- a/example/lib/home/home.dart +++ b/example/lib/home/home.dart @@ -1,3 +1,4 @@ +import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; import 'package:universal_ble/universal_ble.dart'; import 'package:universal_ble_example/data/mock_universal_ble.dart'; @@ -72,11 +73,19 @@ class _MyAppState extends State { } Future _getSystemDevices() async { + // For macOS and iOS, it is recommended to set a filter to get system devices + if (defaultTargetPlatform == TargetPlatform.macOS || + defaultTargetPlatform == TargetPlatform.iOS && + (scanFilter?.withServices ?? []).isEmpty) { + showSnackbar( + "No services filter was set for getting system connected devices. Using default services..."); + } + List devices = await UniversalBle.getSystemDevices( withServices: scanFilter?.withServices, ); if (devices.isEmpty) { - showSnackbar("No Connected Devices Found"); + showSnackbar("No System Connected Devices Found"); } setState(() { _bleDevices.clear(); @@ -191,7 +200,7 @@ class _MyAppState extends State { ), if (BleCapabilities.supportsConnectedDevicesApi) PlatformButton( - text: 'Connected Devices', + text: 'System Devices', onPressed: _getSystemDevices, ), PlatformButton(