コード例 #1
0
        protected IObservable <Beacon> Scan()
        {
            // TODO: switch to background scan
            this.beaconScanner = this.beaconScanner ?? this.adapter
                                 .Scan()
                                 .Where(x => Beacon.IsIBeaconPacket(x.AdvertisementData?.ManufacturerData))
                                 .Select(x => Beacon.Parse(x.AdvertisementData.ManufacturerData, x.Rssi))
                                 .Publish()
                                 .RefCount();

            return(this.beaconScanner);
        }
コード例 #2
0
        IObservable <Beacon> Scan()
        {
            // TODO: switch to background scan
            this.beaconScanner = this.beaconScanner ?? Observable
                                 .Create <Beacon>(ob => this.adapter
                                                  .Scan()
                                                  .Subscribe(sr =>
            {
                var md = sr.AdvertisementData?.ManufacturerData;
                if (md != null && Beacon.IsIBeaconPacket(md))
                {
                    var beacon = Beacon.Parse(md, sr.Rssi);
                    ob.OnNext(beacon);
                }
            })
                                                  )
                                 .Publish()
                                 .RefCount();

            return(this.beaconScanner);
        }