umair13adil / simple_beacons_flutter

A flutter plugin project to range & monitor iBeacons.
Apache License 2.0
35 stars 42 forks source link

setMethodCallHandler never run? #56

Closed barangungor closed 2 years ago

barangungor commented 2 years ago

I want scan beacon devices, wrote the code like example code but i only see 2. print in my console. I can't see 3. print and can't startMonitoring.

print("Beacons DataReceived: ");
    if (Platform.isAndroid) {
      print("Beacons DataReceived: ANDROID ");
      BeaconsPlugin.channel.setMethodCallHandler((call) async {
        print("Beacons DataReceived: " + call.method);
        if (call.method == 'scannerReady') {
    await BeaconsPlugin.startMonitoring();
        }
      });
    } else if (Platform.isIOS) {
      await BeaconsPlugin.startMonitoring();
    }
umair13adil commented 2 years ago

@barangungor Let me look into this issue today.

barangungor commented 2 years ago

@umair13adil Thanks waiting for it.

umair13adil commented 2 years ago

This issue is resolved in version 2.0.5.

barangungor commented 2 years ago

I upgraded to 2.0.5 but still same error.

umair13adil commented 2 years ago

@barangungor Have you tried it in the sample app, after pulling latest changes?

barangungor commented 2 years ago

@umair13adil No, i didn't try sample app but my code same with sample app

final StreamController<String> beaconEventsController =
        StreamController<String>.broadcast();
    if (Platform.isAndroid) {
      BeaconsPlugin.channel.setMethodCallHandler((call) async {
        if (call.method == 'scannerReady') {
          await BeaconsPlugin.startMonitoring();
        }
      });
    } else if (Platform.isIOS) {
      await BeaconsPlugin.startMonitoring();
    }
    await BeaconsPlugin.listenToBeacons(beaconEventsController);
    await BeaconsPlugin.addRegion(
        "iBeacon", "4aa10000-0a46-115f-d97e-5a966a7ddcc4");
    print("Beacons DataReceived: " + BeaconsPlugin.channel.toString());
    beaconEventsController.stream.listen(
        (data) {
          if (data.isNotEmpty) {
            print("Beacons DataReceived: " + data);
          }
        },
        onDone: () {},
        onError: (error) {
          print("Error: $error");
        });
    await BeaconsPlugin.startMonitoring();
barangungor commented 2 years ago

We definitely need to use this code. I added this block and error fixed. Thanks @umair13adil !

if (Platform.isAndroid) {
      //Prominent disclosure
      await BeaconsPlugin.setDisclosureDialogMessage(
          title: "Background Locations",
          message:
              "[This app] collects location data to enable [feature], [feature], & [feature] even when the app is closed or not in use");

      //Only in case, you want the dialog to be shown again. By Default, dialog will never be shown if permissions are granted.
      //await BeaconsPlugin.clearDisclosureDialogShowFlag(false);
    }
barangungor commented 2 years ago

I'm facing this issue again. I can't understand, Sometimes it happens sometimes it doesn't.

cloudbreakstudios commented 1 year ago

This issue appears to have come back! We get past the prominent disclosure, but that's it. Scanning is never started! This used to work in 2.0.0. I've upgraded to 2.0.8 (clean and rebuild) - and it is no longer working! Tested on fully updated Pixel 4.