Событие, когда вход в диапазон маяка и когда выход из диапазона маяка - PullRequest
1 голос
/ 22 января 2020

Я разрабатываю кроссплатформенное (Android, iOS, UWP) приложение с Xamarin и пытаюсь вызвать функцию (вызвать событие) всякий раз, когда мой телефон входит в диапазон маяка и когда он выходит из него

Я использую UniversalBeaconLibrary

и мой код выглядит следующим образом

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UniversalBeacon.Library.Core.Entities;
using UniversalBeacon.Library.NetFramework;
using Windows.Devices.Bluetooth.Advertisement;


namespace BL_Test
{
    class Program
    {
        // Bluetooth Beacons
        private readonly BluetoothLEAdvertisementWatcher _watcher;

        private BeaconManager _beaconManager;
        private static void BeaconManagerOnBeaconAdded(object sender, Beacon beacon)
        {
            if (beacon.BeaconType != Beacon.BeaconTypeEnum.Unknown)
            {
                Console.WriteLine("\nBeacon: " + beacon.BluetoothAddressAsString);
                Console.WriteLine("Type: " + beacon.BeaconType);
                Console.WriteLine("Last Update: " + beacon.Timestamp);
                Console.WriteLine("RSSI: " + beacon.Rssi);
            }
            foreach (var beaconFrame in beacon.BeaconFrames.ToList())
            {
                // Print iBeacons found in the area
                if (beaconFrame is ProximityBeaconFrame)
                {
                    if (((ProximityBeaconFrame)beaconFrame).UuidAsString == "f7826da6-4fa2-4e98-8024-bc5b71e0893e")
                        Console.Title = "Beacon in range";
                    Console.WriteLine("Proximity Beacon Frame (iBeacon compatible)");
                    Console.WriteLine("Uuid: " + ((ProximityBeaconFrame)beaconFrame).UuidAsString);
                    Console.WriteLine("Major: " + ((ProximityBeaconFrame)beaconFrame).MajorAsInt);
                    Console.WriteLine("Minor: " + ((ProximityBeaconFrame)beaconFrame).MinorAsInt);
                }
                else
                {
                    Console.WriteLine("Unknown frame - not parsed by the library, write your own derived beacon frame type!");
                    Console.WriteLine("Payload: " + BitConverter.ToString(((UnknownBeaconFrame)beaconFrame).Payload));
                }
            }
        }

        static void Main(string[] args)
        {
            Program prg = new Program();
            // Construct the Universal Bluetooth Beacon manager
            var provider = new WindowsBluetoothPacketProvider();
            prg._beaconManager = new BeaconManager(provider);
            prg._beaconManager.BeaconAdded += BeaconManagerOnBeaconAdded;


            prg._beaconManager.Start(); //To get realtime beacon updates
            Console.ReadLine();
        }
    }
}

Проблема в том, что _beaconManager.BeaconAdded += BeaconManagerOnBeaconAdded; вызывается только тогда, когда приложение сначала находит маяк, оно никогда вызывается снова

Как вызвать событие (чтобы затем отобразить, находится ли маяк в радиусе действия или нет в уведомлениях), когда телефоны выходят из диапазона маяка и когда он затем снова входит в него?

...