Open haidvams opened 3 years ago
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!
The example in the README is wrong. Use the example from the project itself
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.
It is working for me... maybe your beacon?
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.
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 In the addRegion the first option "myBeacon" is option and you can write what ever you want. The second is the proximityUUID?
@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.
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
final StreamController
_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
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
//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
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:
Very nice, can you send me a link weTransfer with your code, to my email (Pollakis.p6@gmail.com) please?
Thank you!
@PeterPoll you need to specify the region correctly, uuid is case-sensitive
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
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.
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?
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?
Can you search beacon on ios?
IOS device cannot scan device beacon ?