simple_beacons_flutter icon indicating copy to clipboard operation
simple_beacons_flutter copied to clipboard

IOS not working

Open haidvams opened this issue 3 years ago • 16 comments

IOS device cannot scan device beacon ?

haidvams avatar Mar 10 '21 10:03 haidvams

Is working for you on android ? I'm trying and doesn't works for android or ios. If working for your on Android please help me or send me you code.. I'm trying many days now to figure out..

Thank you!

PetrosPoll avatar Mar 11 '21 14:03 PetrosPoll

The example in the README is wrong. Use the example from the project itself

leobispo avatar Mar 17 '21 13:03 leobispo

Also project doesn't work... I'm looking so many days how to create an app that can scan beacons nearby and doing something, like notification.

PetrosPoll avatar Mar 17 '21 13:03 PetrosPoll

It is working for me... maybe your beacon?

leobispo avatar Mar 17 '21 13:03 leobispo

This example working and detect to beacons ? Hmmm my beacon is from a company blueup and from configuration app's company works well.

Can you help me to fix it and show if it works ? Thank you.

PetrosPoll avatar Mar 17 '21 14:03 PetrosPoll

This is the code I am using:

    if (GetPlatform.isAndroid) {
      await BeaconsPlugin.setDisclosureDialogMessage(
          title: "Need Location Permission",
          message: "This app collects location data to work with beacons.");
    }

    BeaconsPlugin.listenToBeacons(beaconEventsController);

    BeaconsPlugin.setDebugLevel(2);
    await BeaconsPlugin.addRegion("myBeacon", uuid);

    beaconEventsController.stream.listen(
        (data) {
          if (data.isNotEmpty) {
            print("Beacons DataReceived: " + data);
          }
        },
        onDone: () {},
        onError: (error) {
          print("Error: $error");
        });

    await BeaconsPlugin.runInBackground(true);
    await BeaconsPlugin.startMonitoring;

    if (GetPlatform.isAndroid) {
      BeaconsPlugin.channel.setMethodCallHandler((call) async {
        await BeaconsPlugin.startMonitoring;
        if (call.method == 'scannerReady') {
          await BeaconsPlugin.startMonitoring;
        }
      });
    }
  }

leobispo avatar Mar 17 '21 15:03 leobispo

@leobispo In the addRegion the first option "myBeacon" is option and you can write what ever you want. The second is the proximityUUID?

PetrosPoll avatar Mar 18 '21 07:03 PetrosPoll

@leobispo I tried also your code but not working for me .. Can you help me more please ? How I can do this working ? I have spent a lot of time and I have nothing since then.

PetrosPoll avatar Mar 18 '21 08:03 PetrosPoll

here my code worked now

import 'dart:async'; import 'dart:convert'; import 'dart:io' show Platform;

import 'package:beacons_plugin/beacons_plugin.dart'; import 'package:device_info/device_info.dart'; import 'package:flutter/material.dart'; import 'package:hrm/main/data/database_helper.dart'; import 'package:hrm/main/data/rest_data.dart'; import 'package:hrm/main/models/user.dart'; import 'package:hrm/theme1/screen/attendance/T1Checkin.dart';

class BeaconScanner extends StatefulWidget { @override _BeaconScanner createState() => _BeaconScanner(); }

class _BeaconScanner extends State<BeaconScanner> { String _beaconResult = 'Get ID device service...'; int _nrMessaggesReceived = 0; var isRunning = false; String _uuid; RestDatasource api = new RestDatasource(); var db = new DatabaseHelper(); final scaffoldKey = new GlobalKey<ScaffoldState>();

final StreamController<String> beaconEventsController = StreamController<String>.broadcast();

_getIdAttendance() async { dynamic id = await api.getDataPublic( '/api/resource/Attendance%20device?fields=["uuid"]&limit_page_length=1');

if (id.isNotEmpty) {
  setState(() {
    _uuid = id.first["uuid"].toString();
    _beaconResult = 'Looking for the device...';
  });
  initPlatformState();
  await BeaconsPlugin.startMonitoring;
} else {
  _showSnackBar("Errors server HRM to get ID devece checkin");
}

}

_onCheckinSubmit() async { String _deviceId = await _getId(); Map dataBody = await {"log_type": "IN", "device_id": _deviceId};

try {
  User user = await db.getUser();
  var res = await api.postPrivateAll(
      '/api/resource/Employee%20Checkin', user.sid, dataBody);
  if (res == true) {
    await Future<void>.delayed(Duration(milliseconds: 500));
    Navigator.pushReplacement(
        context, MaterialPageRoute(builder: (context) => T1Checkin()));
  } else {
    await Future<void>.delayed(Duration(milliseconds: 500));
    Navigator.pop(context);
  }
} catch (e) {
  print("err");
}

}

Future<String> _getId() async { var deviceInfo = DeviceInfoPlugin(); if (Platform.isIOS) { // import 'dart:io' var iosDeviceInfo = await deviceInfo.iosInfo; return iosDeviceInfo.identifierForVendor; // unique ID on iOS } else { var androidDeviceInfo = await deviceInfo.androidInfo; return androidDeviceInfo.androidId; // unique ID on Android } }

void _showSnackBar(String text) { scaffoldKey.currentState .showSnackBar(new SnackBar(content: new Text(text))); }

@override void initState() { super.initState(); _getIdAttendance(); }

@override void dispose() { beaconEventsController.close(); super.dispose(); }

Future initPlatformState() async { if (Platform.isAndroid) { //Prominent disclosure await BeaconsPlugin.setDisclosureDialogMessage( title: "Need Location Permission", message: "This app collects location data to work with beacons.");

  //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);
}

BeaconsPlugin.listenToBeacons(beaconEventsController);
//ios must add uuid you want to scan
await BeaconsPlugin.addRegion(
    "ESP32", _uuid);

beaconEventsController.stream.listen(
    (data) async {
      if (data.isNotEmpty) {
        if (_uuid == jsonDecode(data)["uuid"].toString().toLowerCase()) {
          await BeaconsPlugin.stopMonitoring;
          setState(() {
            _beaconResult = "Đang checkin ...";
          });
          Future.delayed(const Duration(seconds: 1), () => "1");
          _onCheckinSubmit();
        } else {
          setState(() {
            _nrMessaggesReceived++;
          });
        }
      }
    },
    onDone: () {},
    onError: (error) {
      print("Error: $error");
    });

// Send 'true' to run in background
await BeaconsPlugin.runInBackground(true);

if (Platform.isAndroid) {
  BeaconsPlugin.channel.setMethodCallHandler((call) async {
    if (call.method == 'scannerReady') {
      await BeaconsPlugin.startMonitoring;
      setState(() {
        isRunning = true;
      });
    }
  });
} else if (Platform.isIOS) {
  await BeaconsPlugin.startMonitoring;
  setState(() {
    isRunning = true;
  });
}

if (!mounted) return;

}

Future _onBackPressed() { return showDialog( context: context, builder: (context) => new AlertDialog( title: new Text('Are you sure?'), content: new Text('Do you want to exit Checkin'), actions: <Widget>[ new GestureDetector( onTap: () => Navigator.of(context).pop(false), child: Text("NO"), ), SizedBox(height: 16), new GestureDetector( onTap: () async { try { await BeaconsPlugin.stopMonitoring; } catch (e) { // _showSnackBar(e.toString()); } await Future.delayed(Duration(milliseconds: 500));

              return Navigator.of(context).pop(true);
            },
            child: Text("YES"),
          ),
        ],
      ),
    ) ??
    false;

}

@override Widget build(BuildContext context) { return WillPopScope( onWillPop: _onBackPressed, child: Scaffold( key: scaffoldKey, appBar: AppBar( title: Text('Checkin'), backgroundColor: Color(0xFF3281FF), centerTitle: true, ), body: Center( child: Column( crossAxisAlignment: CrossAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center, children: <Widget>[ Text('$_beaconResult'), Padding( padding: EdgeInsets.all(10.0), ), Text('$_nrMessaggesReceived'), SizedBox( height: 20.0, ), // Visibility( // visible: isRunning, // child: RaisedButton( // onPressed: () async { // if (Platform.isAndroid) { // await BeaconsPlugin.stopMonitoring; // // setState(() { // isRunning = false; // }); // } // }, // child: Text('Stop Scanning', style: TextStyle(fontSize: 20)), // ), // ), // SizedBox( // height: 20.0, // ), // Visibility( // visible: !isRunning, // child: RaisedButton( // onPressed: () async { // initPlatformState(); // await BeaconsPlugin.startMonitoring; // // setState(() { // isRunning = true; // _beaconResult = "Đang tìm device..."; // }); // }, // child: Text('Start Scanning', style: TextStyle(fontSize: 20)), // ), // ) ], ), ), ), ); } }

haidvams avatar Apr 03 '21 04:04 haidvams

Very nice, can you send me a link weTransfer with your code, to my email ([email protected]) please?

Thank you!

PetrosPoll avatar Apr 03 '21 13:04 PetrosPoll

@PeterPoll you need to specify the region correctly, uuid is case-sensitive

sutogan4ik avatar Apr 10 '21 13:04 sutogan4ik

by the way, the implementation for android does not react at all to the scanned region, and in iOS you need to specify the region, otherwise the scan result will be ignored. in my case, I even had to change the uuid of the beacon

sutogan4ik avatar Apr 10 '21 13:04 sutogan4ik

by the way, the implementation for android does not react at all to the scanned region, and in iOS you need to specify the region, otherwise the scan result will be ignored. in my case, I even had to change the uuid of the beacon

Are you able to create a mini prototype of your working version? I have now spent a few days investigating why my iBeacon is not displaying on iOS.

I have setup the beacons UUID (iBeacon) and configured the code to match (also case sensitive as you've suggested). Project swift file and plist has been updated per example. Working fine on Android but absolutely no response on iOS. The location permission in settings is set to 'Always@ and there are no errors in debug.

Using BeaconSet+ app i can see the beacon straight away on the device.

I am out of ideas with this package at this point.

cloudbreakstudios avatar Jun 05 '21 11:06 cloudbreakstudios

So I just got this (kinda) working.. it seems that as soon as I add in more than one region to scan, iOS doesnt detect any!

This fails.. await BeaconsPlugin.addRegion("MyBeacon", "696e6974-7379-7300-0000-0070616e6963"); await BeaconsPlugin.addRegion("MyBeacon", "696e6974-7379-7300-0000-000000000001");

whereas this works and detects the first beacon.. await BeaconsPlugin.addRegion("MyBeacon", "696e6974-7379-7300-0000-0070616e6963"); //await BeaconsPlugin.addRegion("MyBeacon", "696e6974-7379-7300-0000-000000000001"); <-- commented out

Ideally I need to be able to scan for several regions (note the last 12 chars are different) as configuring the major/minor creates us an limitation that is not ideal to our use case.

Has anyone got this working where multiple regions work?

cloudbreakstudios avatar Jun 05 '21 13:06 cloudbreakstudios

Hello,

you put uuid in region and in ibeacon config?

i can find with android, but with iOS I can’t see any beacon. And I don’t have any error.

Any suggestion?

gordett avatar Jan 21 '22 00:01 gordett

Can you search beacon on ios?

gordett avatar Jan 21 '22 23:01 gordett