예제 #1
0
 internal void PeripheralManagerDidUpdateState()
 {
     if (peripheralManager.state == CBPeripheralManagerState.PoweredOn)
     {
         Log("Powered ON.");
         Dictionary <object, object> data = beaconRegion.PeripheralData(-50);
         peripheralManager.StartAdvertising(data);
         Log("Advertising.");
     }
     else if (peripheralManager.state == CBPeripheralManagerState.PoweredOff)
     {
         Log("Powered OFF.");
         peripheralManager.StopAdvertising();
     }
 }
예제 #2
0
        protected override void StopAdvertising()
        {
            // remove service
            try
            {
                SensusServiceHelper.Get().Logger.Log("Removing service.", LoggingLevel.Normal, GetType());
                _bluetoothPeripheralManager?.RemoveService(_deviceIdService);
            }
            catch (Exception ex)
            {
                SensusServiceHelper.Get().Logger.Log("Exception while removing service " + _deviceIdService.UUID + ":  " + ex.Message, LoggingLevel.Normal, GetType());
            }

            // stop advertising
            try
            {
                SensusServiceHelper.Get().Logger.Log("Stopping peripheral advertising.", LoggingLevel.Normal, GetType());
                _bluetoothPeripheralManager?.StopAdvertising();
            }
            catch (Exception ex)
            {
                SensusServiceHelper.Get().Logger.Log("Exception while stopping advertising:  " + ex.Message, LoggingLevel.Normal, GetType());
            }
            finally
            {
                _bluetoothPeripheralManager = null;
            }
        }
예제 #3
0
        public void Stop()
        {
            if (_peripheralManager == null)
            {
                // not started
                return;
            }

            _peripheralManager.StopAdvertising();
            Covi.Features.BluetoothTracing.TracingState.Instance.SetAdvertisingState(false);
            _enabled = false;
            _logger.LogDebug("Advertising - stopped");
        }
 public override void StateUpdated(CBPeripheralManager peripheral)
 {
     if (peripheral.State == CBPeripheralManagerState.PoweredOn)
     {
         Console.WriteLine("powered on");
         peripheral.StartAdvertising(beaconPeripheralRegion);
     }
     else if (peripheral.State == CBPeripheralManagerState.PoweredOff)
     {
         Console.WriteLine("powered off");
         peripheral.StopAdvertising();
     }
     else if (peripheral.State == CBPeripheralManagerState.Unsupported)
     {
         Console.WriteLine("unsupported");
     }
 }
예제 #5
0
        private void DidStateUpdated(object sender, EventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("DidStateUpdated");
            CBPeripheralManager trasmitter = sender as CBPeripheralManager;

            if (trasmitter.State < CBPeripheralManagerState.PoweredOn)
            {
                System.Diagnostics.Debug.WriteLine("Bluetooth must be enabled");
                // new UIAlertView("Bluetooth must be enabled", "To configure your device as a beacon", null, "OK", null).Show();
                return;
            }

            if (_transmitterFlg)
            {
                CLBeaconRegion region  = new CLBeaconRegion(new NSUuid(AppConstants.iBeaconAppUuid), ushort.Parse(_userData.Major), ushort.Parse(_userData.Minor), _userData.UserUuid);
                NSNumber       txPower = new NSNumber(-59);
                trasmitter.StartAdvertising(region.GetPeripheralData(txPower));
            }
            else
            {
                trasmitter.StopAdvertising();
            }
        }
예제 #6
0
        public void AdvertiseData()
        {
            var uui      = new CBUUID[] { CBUUID.FromString("E20A39F4-73F5-4BC4-A12F-17D1AD07A961") };
            var nsArray  = NSArray.FromObjects(uui);
            var nsObject = NSObject.FromObject(nsArray);

            var manufacturerDataBytes = new byte[6] {
                5, 255, 76, 0, 25, 35
            };

            var advertisementData = new NSDictionary(
                CBAdvertisement.DataLocalNameKey, "id1",
                CBAdvertisement.DataServiceUUIDsKey, nsObject,
                CBAdvertisement.DataManufacturerDataKey, NSData.FromArray(manufacturerDataBytes),
                CBAdvertisement.DataServiceDataKey, "Sent data");

            if (cbPeriphMang.Advertising)
            {
                cbPeriphMang.StopAdvertising();
            }

            cbPeriphMang.StartAdvertising(advertisementData);
        }
예제 #7
0
 /// <summary>
 /// iBeaconの発信を停止する処理
 /// </summary>
 public void StopTransmission()
 {
     _peripheralManager.StopAdvertising();
 }
예제 #8
0
 public void StopAdvertisingBeacons()
 {
     _beaconTransmitter.StopAdvertising();
 }
예제 #9
0
 public void StopAdvertising()
 {
     _peripheralMgr.StopAdvertising();
 }
예제 #10
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            this.Title = "Configure";

            enabledSwitch.ValueChanged += (sender, e) => {
                enabled = enabledSwitch.On;
            };

            uuidTextField.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
            uuidTextField.InputView        = new UuidPickerView(uuidTextField);
            uuidTextField.EditingDidBegin += HandleEditingDidBegin;
            uuidTextField.EditingDidEnd   += (sender, e) => {
                uuid = new NSUuid(uuidTextField.Text);
                NavigationItem.RightBarButtonItem = saveButton;
            };
            uuidTextField.Text = uuid.AsString();

            majorTextField.KeyboardType     = UIKeyboardType.NumberPad;
            majorTextField.ReturnKeyType    = UIReturnKeyType.Done;
            majorTextField.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
            majorTextField.EditingDidBegin += HandleEditingDidBegin;
            majorTextField.EditingDidEnd   += (sender, e) => {
                major = numberFormatter.NumberFromString(majorTextField.Text);
                NavigationItem.RightBarButtonItem = saveButton;
            };

            minorTextField.KeyboardType     = UIKeyboardType.NumberPad;
            minorTextField.ReturnKeyType    = UIReturnKeyType.Done;
            minorTextField.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
            minorTextField.EditingDidBegin += HandleEditingDidBegin;
            minorTextField.EditingDidEnd   += (sender, e) => {
                minor = numberFormatter.NumberFromString(minorTextField.Text);
                NavigationItem.RightBarButtonItem = saveButton;
            };

            measuredPowerTextField.KeyboardType     = UIKeyboardType.NumberPad;
            measuredPowerTextField.ReturnKeyType    = UIReturnKeyType.Done;
            measuredPowerTextField.AutoresizingMask = UIViewAutoresizing.FlexibleWidth;
            measuredPowerTextField.EditingDidBegin += HandleEditingDidBegin;
            measuredPowerTextField.EditingDidEnd   += (sender, e) => {
                power = numberFormatter.NumberFromString(measuredPowerTextField.Text);
                NavigationItem.RightBarButtonItem = saveButton;
            };

            doneButton = new UIBarButtonItem(UIBarButtonSystemItem.Done, (sender, e) => {
                uuidTextField.ResignFirstResponder();
                majorTextField.ResignFirstResponder();
                minorTextField.ResignFirstResponder();
                measuredPowerTextField.ResignFirstResponder();
                TableView.ReloadData();
            });

            saveButton = new UIBarButtonItem(UIBarButtonSystemItem.Save, (sender, e) => {
                if (peripheralManager.State < CBPeripheralManagerState.PoweredOn)
                {
                    new UIAlertView("Bluetooth must be enabled", "To configure your device as a beacon", null, "OK", null).Show();
                    return;
                }

                if (enabled)
                {
                    CLBeaconRegion region = Helpers.CreateRegion(uuid, major, minor);
                    if (region != null)
                    {
                        peripheralManager.StartAdvertising(region.GetPeripheralData(power));
                    }
                }
                else
                {
                    peripheralManager.StopAdvertising();
                }

                NavigationController.PopViewControllerAnimated(true);
            });

            NavigationItem.RightBarButtonItem = saveButton;
        }