Implement isScanning api (#188)
* Implement isScanning api * Improve IOS scanning api * Update Readme and Changelog
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
// Autogenerated from Pigeon (v26.0.5), do not edit directly.
|
||||
// Autogenerated from Pigeon (v26.1.0), do not edit directly.
|
||||
// See also: https://pub.dev/packages/pigeon
|
||||
|
||||
#undef _HAS_EXCEPTIONS
|
||||
@@ -623,6 +623,27 @@ void UniversalBlePlatformChannel::SetUp(
|
||||
channel.SetMessageHandler(nullptr);
|
||||
}
|
||||
}
|
||||
{
|
||||
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.isScanning" + prepended_suffix, &GetCodec());
|
||||
if (api != nullptr) {
|
||||
channel.SetMessageHandler([api](const EncodableValue& message, const flutter::MessageReply<EncodableValue>& reply) {
|
||||
try {
|
||||
ErrorOr<bool> output = api->IsScanning();
|
||||
if (output.has_error()) {
|
||||
reply(WrapError(output.error()));
|
||||
return;
|
||||
}
|
||||
EncodableList wrapped;
|
||||
wrapped.push_back(EncodableValue(std::move(output).TakeValue()));
|
||||
reply(EncodableValue(std::move(wrapped)));
|
||||
} catch (const std::exception& exception) {
|
||||
reply(WrapError(exception.what()));
|
||||
}
|
||||
});
|
||||
} else {
|
||||
channel.SetMessageHandler(nullptr);
|
||||
}
|
||||
}
|
||||
{
|
||||
BasicMessageChannel<> channel(binary_messenger, "dev.flutter.pigeon.universal_ble.UniversalBlePlatformChannel.connect" + prepended_suffix, &GetCodec());
|
||||
if (api != nullptr) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// Autogenerated from Pigeon (v26.0.5), do not edit directly.
|
||||
// Autogenerated from Pigeon (v26.1.0), do not edit directly.
|
||||
// See also: https://pub.dev/packages/pigeon
|
||||
|
||||
#ifndef PIGEON_UNIVERSAL_BLE_G_H_
|
||||
@@ -352,6 +352,7 @@ class UniversalBlePlatformChannel {
|
||||
virtual void DisableBluetooth(std::function<void(ErrorOr<bool> reply)> result) = 0;
|
||||
virtual std::optional<FlutterError> StartScan(const UniversalScanFilter* filter) = 0;
|
||||
virtual std::optional<FlutterError> StopScan() = 0;
|
||||
virtual ErrorOr<bool> IsScanning() = 0;
|
||||
virtual std::optional<FlutterError> Connect(const std::string& device_id) = 0;
|
||||
virtual std::optional<FlutterError> Disconnect(const std::string& device_id) = 0;
|
||||
virtual void SetNotifiable(
|
||||
|
||||
@@ -212,6 +212,15 @@ std::optional<FlutterError> UniversalBlePlugin::StopScan() {
|
||||
}
|
||||
};
|
||||
|
||||
ErrorOr<bool> UniversalBlePlugin::IsScanning() {
|
||||
if (bluetooth_le_watcher_ != nullptr) {
|
||||
try {
|
||||
return bluetooth_le_watcher_.Status() == BluetoothLEAdvertisementWatcherStatus::Started;
|
||||
} catch (...) {}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
ErrorOr<int64_t>
|
||||
UniversalBlePlugin::GetConnectionState(const std::string &device_id) {
|
||||
const auto it = connected_devices_.find(str_to_mac_address(device_id));
|
||||
|
||||
@@ -158,6 +158,7 @@ namespace universal_ble
|
||||
ErrorOr<int64_t> GetConnectionState(const std::string &device_id) override;
|
||||
std::optional<FlutterError> StartScan(const UniversalScanFilter *filter) override;
|
||||
std::optional<FlutterError> StopScan() override;
|
||||
ErrorOr<bool> IsScanning() override;
|
||||
std::optional<FlutterError> Connect(const std::string &device_id) override;
|
||||
std::optional<FlutterError> Disconnect(const std::string &device_id) override;
|
||||
void DiscoverServices(
|
||||
|
||||
Reference in New Issue
Block a user