Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IOS not working #42

Open
haidvams opened this issue Mar 10, 2021 · 16 comments
Open

IOS not working #42

haidvams opened this issue Mar 10, 2021 · 16 comments

Comments

@haidvams
Copy link

IOS device cannot scan device beacon ?

@PetrosPoll
Copy link

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!

@leobispo
Copy link

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

@PetrosPoll
Copy link

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.

@leobispo
Copy link

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

@PetrosPoll
Copy link

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.

@leobispo
Copy link

leobispo commented Mar 17, 2021

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

@PetrosPoll
Copy link

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

@PetrosPoll
Copy link

@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.

@haidvams
Copy link
Author

haidvams commented Apr 3, 2021

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 {
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();

final StreamController beaconEventsController =
StreamController.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 _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: [
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: [
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)),
// ),
// )
],
),
),
),
);
}
}

@PetrosPoll
Copy link

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

Thank you!

@sutogan4ik
Copy link

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

@sutogan4ik
Copy link

sutogan4ik commented Apr 10, 2021

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

@cloudbreakstudios
Copy link

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
Copy link

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?

@gordett
Copy link

gordett commented Jan 21, 2022

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
Copy link

gordett commented Jan 21, 2022

Can you search beacon on ios?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants