public static void CheckInit(Dictionary<string, string> info) { if (peripheralManager != null) return; _info = info; NSUuid id; int i = 0; foreach (KeyValuePair<string, string> kvp in _info) { try { id = new NSUuid (kvp.Value); // beaconId); } catch (Exception err) { Global.ShowNotification (Plugin.Toasts.ToastNotificationType.Error, "iBeacon", "iBeacons UUID is wrong!"); return; } beaconRegion.Add (new CLBeaconRegion (id, kvp.Key)); //regionName); } peripheralDelegate = new PeripheralManagerDelegate (); peripheralDelegate.StateUpdatedEvent += PeripheralDelegate_StateUpdatedEvent; peripheralManager = new CBPeripheralManager (peripheralDelegate, DispatchQueue.DefaultGlobalQueue, new NSDictionary ()); //peripheralManager = new CBPeripheralManager (ICBPeripheralManagerDelegate, DispatchQueue.DefaultGlobalQueue, new NSDictionary()); //peripheralManager.StateUpdated += HandleStateUpdated; }
public BeaconService() { _connection = DependencyService.Resolve <SQLiteConnectionProvider>().GetConnection(); _connection.CreateTable <BeaconDataModel>(); _userDataService = DependencyService.Resolve <UserDataService>(); _userData = _userDataService.Get(); _httpDataService = DependencyService.Resolve <HttpDataService>(); _uploadTimer = new MinutesTimer(_userData.GetJumpHashTimeDifference()); _uploadTimer.Start(); _uploadTimer.TimeOutEvent += TimerUpload; _beaconTransmitter = new CBPeripheralManager(); _beaconTransmitter.AdvertisingStarted += DidAdvertisingStarted; _beaconTransmitter.StateUpdated += DidStateUpdated; _listOfCLBeaconRegion = new List <CLBeaconRegion>(); _fieldRegion = new CLBeaconRegion(new NSUuid(AppConstants.iBeaconAppUuid), ""); _fieldRegion.NotifyEntryStateOnDisplay = true; _fieldRegion.NotifyOnEntry = true; _fieldRegion.NotifyOnExit = true; // Monitoring _beaconManager = new CLLocationManager(); _beaconManager.DidDetermineState += DetermineStateForRegionComplete; _beaconManager.RegionEntered += EnterRegionComplete; _beaconManager.RegionLeft += ExitRegionComplete; _beaconManager.PausesLocationUpdatesAutomatically = false; _beaconManager.AllowsBackgroundLocationUpdates = true; _beaconManager.ShowsBackgroundLocationIndicator = true; _beaconManager.DidRangeBeacons += DidRangeBeconsInRegionComplete; _beaconManager.AuthorizationChanged += HandleAuthorizationChanged; }
public void InitializeService() { if (peripheralManager == null) { peripheralManager = beaconconfig(); } }
public override void StateUpdated(CBPeripheralManager peripheral) { if (peripheral.State == CBPeripheralManagerState.PoweredOn) { Console.WriteLine("powered on"); } }
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; } }
public BeaconService(ISQLiteConnectionProvider sqliteConnectionProvider) { _connection = sqliteConnectionProvider.GetConnection(); _connection.CreateTable <BeaconDataModel>(); _beaconTransmitter = new CBPeripheralManager(); _beaconTransmitter.StateUpdated += DidStateUpdated; _listOfCLBeaconRegion = new List <CLBeaconRegion>(); _fieldRegion = new CLBeaconRegion(new NSUuid(AppConstants.iBeaconAppUuid), ""); _fieldRegion.NotifyEntryStateOnDisplay = true; _fieldRegion.NotifyOnEntry = true; _fieldRegion.NotifyOnExit = true; // Monitoring _locationManager = new CLLocationManager(); if (CLLocationManager.LocationServicesEnabled) { _locationManager.Delegate = this; _locationManager.PausesLocationUpdatesAutomatically = false; _locationManager.ShowsBackgroundLocationIndicator = true; _locationManager.DistanceFilter = 1.0; _locationManager.AllowsBackgroundLocationUpdates = true; _locationManager.DidRangeBeacons += DidRangeBeconsInRegionComplete; _locationManager.AuthorizationChanged += HandleAuthorizationChanged; _locationManager.RequestAlwaysAuthorization(); } }
public void Initialize(Action onStateUpdated) { _onInitialized = onStateUpdated; _peripheralManager = new CBPeripheralManager(this, null); _peripheralManager.StateUpdated += (sender, args) => StateUpdated(); RequestHandler = new BluetoothServerRequesthandler(_peripheralManager); }
void ConfigureView() { // Update the user interface for the detail item if (IsViewLoaded && detailItem != null) { detailDescriptionLabel.Text = detailItem.ToString(); } this.Title = detailItem.Code; if(peripheralMgr != null) { peripheralMgr.StopAdvertising(); } else { peripheralDelegate = new BTPeripheralDelegate(); peripheralMgr = new CBPeripheralManager(peripheralDelegate, DispatchQueue.DefaultGlobalQueue); } beaconUUID = new NSUuid(detailItem.UUID); beaconRegion = new CLBeaconRegion(beaconUUID, (ushort)detailItem.Major, (ushort)detailItem.Minor, beaconId); //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away var power = new NSNumber(-59); peripheralData = beaconRegion.GetPeripheralData(power); peripheralMgr.StartAdvertising(peripheralData); QRCode.LoadUrl(GenerateQRCodeUrl(detailItem.ToString(), QRCodeSize.Medium, QRErrorCorrection.H)); }
void ConfigureView() { // Update the user interface for the detail item if (IsViewLoaded && detailItem != null) { detailDescriptionLabel.Text = detailItem.ToString(); } this.Title = detailItem.Code; if (peripheralMgr != null) { peripheralMgr.StopAdvertising(); } else { peripheralDelegate = new BTPeripheralDelegate(); peripheralMgr = new CBPeripheralManager(peripheralDelegate, DispatchQueue.DefaultGlobalQueue); } beaconUUID = new NSUuid(detailItem.UUID); beaconRegion = new CLBeaconRegion(beaconUUID, (ushort)detailItem.Major, (ushort)detailItem.Minor, beaconId); //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away var power = new NSNumber(-59); peripheralData = beaconRegion.GetPeripheralData(power); peripheralMgr.StartAdvertising(peripheralData); QRCode.LoadUrl(GenerateQRCodeUrl(detailItem.ToString(), QRCodeSize.Medium, QRErrorCorrection.H)); }
public void StartAdvertising(CBPeripheralManager peripheralManager) { var userSettings = new UserSettings(); var advertisingData = CreateAdvertisementData(userSettings.Name, BluetoothServiceUuid.ChatServiceUuid); peripheralManager.StartAdvertising(advertisingData); }
public Task CreatePeripheral() { peripheralManager = new CBPeripheralManager(this, DispatchQueue.CurrentQueue, InitOptions); servicesList?.Clear(); characteristicsList?.Clear(); return(Task.CompletedTask); }
public Advertiser() { _peripheralManager = new CBPeripheralManager(); _peripheralManager.StateUpdated += HandleStateUpdated; _peripheralManager.ReadRequestReceived += HandleReadRequestReceived; _logger = Covi.Logs.Logger.Get(this); }
public static IObservable <Unit> WhenReady(this CBPeripheralManager manager) => Observable.Create <Unit>(ob => { var handler = new EventHandler((sender, args) => { if (manager.State == CBPeripheralManagerState.PoweredOn) { ob.Respond(Unit.Default); } else { ob.OnError(new ArgumentException("Adapter state is invalid - " + manager.State)); } }); switch (manager.State) { case CBPeripheralManagerState.Unknown: manager.StateUpdated += handler; break; case CBPeripheralManagerState.PoweredOn: ob.Respond(Unit.Default); break; default: ob.OnError(new ArgumentException("Adapter state is invalid - " + manager.State)); break; } return(() => manager.StateUpdated -= handler); });
public GattService(CBPeripheralManager manager, string uuid, bool primary) { this.manager = manager; this.Native = new CBMutableService(CBUUID.FromString(uuid), primary); this.characteristics = new List <GattCharacteristic>(); this.Uuid = uuid; this.Primary = primary; }
public override void StateUpdated(CBPeripheralManager peripheral) { if (peripheral.State == CBPeripheralManagerState.PoweredOn) { Console.WriteLine("Beacon Debug: powered on"); peripheralMgr.StartAdvertising(peripheralData); } }
public GattService(CBPeripheralManager manager, IGattServer server, Guid serviceUuid, bool primary) : base(server, serviceUuid, primary) { this.manager = manager; #if __TVOS__ #else this.Native = new CBMutableService(serviceUuid.ToCBUuid(), primary); #endif }
public ViewController(IntPtr handle) : base(handle) { del = new ChoirCBCentralManagerDelegate(); manager = new CBCentralManager (del, DispatchQueue.CurrentQueue); peripheralManagerDelegate = new ChoirCBPeripheralManagerDelegate (); peripheral = new CBPeripheralManager (peripheralManagerDelegate, DispatchQueue.CurrentQueue); }
public override void StateUpdated(CBPeripheralManager peripheral) { if (peripheral.State == CBPeripheralManagerState.PoweredOn) { BeaconState = peripheral.State; Advertising = peripheral.Advertising; Console.WriteLine("powered on"); } }
public void Dispose() { if (_PeripheralManager == null) { return; } _PeripheralManager.Dispose(); _PeripheralManager = null; }
public ConfigurationViewController (IntPtr handle) : base (handle) { var peripheralDelegate = new PeripheralManagerDelegate (); peripheralManager = new CBPeripheralManager (peripheralDelegate, DispatchQueue.DefaultGlobalQueue); numberFormatter = new NSNumberFormatter () { NumberStyle = NSNumberFormatterStyle.Decimal }; uuid = Defaults.DefaultProximityUuid; power = Defaults.DefaultPower; }
public void Start(BleDevice device, BleCharacteristic[] characteristics) { string dataServiceUUIDsKey = "71DA3FD1-7E10-41C1-B16F-4430B5060000"; string customBeaconServiceUUIDsKey = "71DA3FD1-7E10-41C1-B16F-4430B5060001"; string customBeaconCharacteristicUUIDKey = "71DA3FD1-7E10-41C1-B16F-4430B5060002"; string identifier = "71DA3FD1-7E10-41C1-B16F-4430B5060003"; peripheralManager = new CBPeripheralManager(this, DispatchQueue.DefaultGlobalQueue); peripheralManager.AdvertisingStarted += (sender, e) => { if (e.Error != null) { System.Diagnostics.Debug.WriteLine(string.Format("*** BleServer -> Advertising error: {0}", e.Error.Description)); } else { System.Diagnostics.Debug.WriteLine("*** BleServer -> We are advertising."); } }; var customBeaconServiceUUID = CBUUID.FromString(customBeaconServiceUUIDsKey); var customBeaconCharacteristicUUID = CBUUID.FromString(customBeaconCharacteristicUUIDKey); var service = new CBMutableService(customBeaconServiceUUID, true); var dataUUID = NSData.FromString(identifier, NSStringEncoding.UTF8); var characteristic = new CBMutableCharacteristic( customBeaconCharacteristicUUID, CBCharacteristicProperties.Read, dataUUID, CBAttributePermissions.Readable); service.Characteristics = new CBCharacteristic[] { characteristic }; peripheralManager.AddService(service); var localName = new NSString("CustomBeacon"); //var advertisingData = new NSDictionary( CBAdvertisement.DataLocalNameKey, localName, // CBAdvertisement.IsConnectable, false, // CBAdvertisement.DataManufacturerDataKey, CBUUID.FromString(dataServiceUUIDsKey), // CBAdvertisement.DataServiceUUIDsKey, CBUUID.FromString(dataServiceUUIDsKey)); //peripheralManager.StartAdvertising(advertisingData); var UUI = new CBUUID[] { CBUUID.FromString("71DA3FD1-7E10-41C1-B16F-4430B5060000") }; NSArray arry = NSArray.FromObjects(UUI); var test = NSObject.FromObject(arry); var ad = new NSDictionary(CBAdvertisement.DataServiceUUIDsKey, test); peripheralManager.StartAdvertising(ad); }
public override void AdvertisingStarted(CBPeripheralManager peripheral, NSError error) { if (error == null) { AdvertiseStartSuccess?.Invoke(this, new AdvertiseStartEventArgs(AdvertiseStatus.None)); } else { AdvertiseStartFailed?.Invoke(this, new AdvertiseStartEventArgs(AdvertiseStatus.InternalError)); } }
private Task <PermissionStatus> RequestBluetoothAsync() { var manager = new CBPeripheralManager(); var tcs = new TaskCompletionSource <PermissionStatus>(manager); manager.StateUpdated += StatusCollback; return(tcs.Task.ReturnInTimeoutAsync(PermissionStatus.Unknown, PermissionTimeout)); void StatusCollback(object sender, EventArgs e) { var state = manager.State; manager.StateUpdated -= StatusCollback; var result = PermissionStatus.Unknown; switch (state) { case CBPeripheralManagerState.PoweredOff: case CBPeripheralManagerState.Unsupported: result = PermissionStatus.Disabled; break; case CBPeripheralManagerState.PoweredOn: result = PermissionStatus.Granted; break; case CBPeripheralManagerState.Unauthorized: result = PermissionStatus.Denied; break; case CBPeripheralManagerState.Resetting: default: result = PermissionStatus.Unknown; break; } switch (CBPeripheralManager.AuthorizationStatus) { case CBPeripheralManagerAuthorizationStatus.Denied: case CBPeripheralManagerAuthorizationStatus.NotDetermined: result = PermissionStatus.Denied; break; case CBPeripheralManagerAuthorizationStatus.Restricted: result = PermissionStatus.Restricted; break; } manager.Dispose(); manager = null; tcs.SetResult(result); } }
public override void AdvertisingStarted(CBPeripheralManager peripheral, NSError error) { if (error == null) { SensusServiceHelper.Get().Logger.Log("Advertising started.", LoggingLevel.Normal, GetType()); } else { SensusServiceHelper.Get().Logger.Log("Error starting advertising: " + error, LoggingLevel.Normal, GetType()); } }
public ConfigurationViewController(IntPtr handle) : base(handle) { var peripheralDelegate = new PeripheralManagerDelegate(); peripheralManager = new CBPeripheralManager(peripheralDelegate, DispatchQueue.DefaultGlobalQueue); numberFormatter = new NSNumberFormatter() { NumberStyle = NSNumberFormatterStyle.Decimal }; uuid = Defaults.DefaultProximityUuid; power = Defaults.DefaultPower; }
void Advertise() { // don't advertise and monitor at the same time StopMonitor(); if ((peripheralManager != null) && (peripheralManager.isAdvertising)) { Log("Already advertising."); return; } pmDelegate = new PeripheralManagerDelegate(this); peripheralManager = new CBPeripheralManager(pmDelegate, null); }
protected override void StartAdvertising() { try { _bluetoothPeripheralManager = new CBPeripheralManager(new iOSBluetoothDeviceProximityProbePeripheralManagerDelegate(_deviceIdService, _deviceIdCharacteristic, this), new DispatchQueue("ble"), NSDictionary.FromObjectAndKey(NSNumber.FromBoolean(false), CBPeripheralManager.OptionShowPowerAlertKey)); // the base class handles prompting using to turn on bluetooth and stops the probe if the user does not. } catch (Exception ex) { SensusServiceHelper.Get().Logger.Log("Exception while starting advertising: " + ex.Message, LoggingLevel.Normal, GetType()); } }
public void speak() { var monkeyUUID = new NSUuid(uuid_person); var beaconRegion2 = new CLBeaconRegion(monkeyUUID, "Person"); //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away var power = new NSNumber(-59); NSMutableDictionary peripheralData = beaconRegion2.GetPeripheralData(power); peripheralDelegate = new BTPeripheralDelegate(); peripheralMgr = new CBPeripheralManager(peripheralDelegate, DispatchQueue.DefaultGlobalQueue); peripheralMgr.StartAdvertising(peripheralData); }
public CBPeripheralManager beaconconfig() { try { var peripheralDelegate = new PeripheralManagerDelegate(); peripheralManager = new CBPeripheralManager(peripheralDelegate, DispatchQueue.DefaultGlobalQueue); return(peripheralManager); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Error is " + ex.Message); return(null); } }
private void Initialize() { var beaconId = BeaconInfo.BeaconUuid;// + _phoneNumber; var beaconUUID = new NSUuid(beaconId); var beaconRegion = new CLBeaconRegion(beaconUUID, _phoneNumber); //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away var power = new NSNumber(-59); _peripheralData = beaconRegion.GetPeripheralData(power); _peripheralDelegate = new BTPeripheralDelegate(); _peripheralMgr = new CBPeripheralManager(_peripheralDelegate, DispatchQueue.DefaultGlobalQueue); //_peripheralMgr.StartAdvertising(_peripheralData); }
public BleStates Available() { var manager = new CBPeripheralManager(); // already authorized if (CBPeripheralManager.AuthorizationStatus == CBPeripheralManagerAuthorizationStatus.Authorized) { return((manager.State == CBPeripheralManagerState.PoweredOn) ? BleStates.On : BleStates.Off); } // request auth //manager.respo return(BleStates.On); }
public void Start(string UUID) { var proximityUUID = new NSUuid("12345678-1234-1234-1234-123456780001"); var beaconRegion = new CLBeaconRegion(proximityUUID, 100, 1, "Whatever"); //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away var power = new NSNumber(-59); NSMutableDictionary peripheralData = beaconRegion.GetPeripheralData(power); peripheralDelegate = new BTPeripheralDelegate(peripheralData); peripheralMgr = new CBPeripheralManager(peripheralDelegate, DispatchQueue.DefaultGlobalQueue); Console.WriteLine("Beacon Debug: " + "Started Advertising:" + UUID); ShowAlert("Started Advertising:" + UUID, 5); }
protected override void StartAdvertising() { SensusContext.Current.MainThreadSynchronizer.ExecuteThreadSafe(() => { try { _bluetoothPeripheralManager = new CBPeripheralManager(new iOSBluetoothDeviceProximityProbePeripheralManagerDelegate(this), DispatchQueue.MainQueue, NSDictionary.FromObjectAndKey(NSNumber.FromBoolean(false), CBPeripheralManager.OptionShowPowerAlertKey)); // the base class handles prompting using to turn on bluetooth and stops the probe if the user does not. } catch (Exception ex) { SensusServiceHelper.Get().Logger.Log("Exception while starting advertising: " + ex.Message, LoggingLevel.Normal, GetType()); } }); }
public GattCharacteristic(CBPeripheralManager manager, IGattService service, Guid characteristicUuid, CharacteristicProperties properties, GattPermissions permissions) : base(service, characteristicUuid, properties, permissions) { this.manager = manager; this.subscribers = new ConcurrentDictionary <NSUuid, IDevice>(); this.Native = new CBMutableCharacteristic( characteristicUuid.ToCBUuid(), properties.ToNative(), null, (CBAttributePermissions)(int)permissions // TODO ); }
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"); } }
public RemoteXServerForIos() { CBUUID[] cBUUIDs = new CBUUID[1]; CBUUID cBUUID = CBUUID.FromString("AD86E9A5-AB95-4D75-A4BC-2A969F26E028"); cBPeripheralManager = new CBPeripheralManager(); remoteService = new CBMutableService(cBUUID, true); cBPeripheralManager.AddService(remoteService); cBUUIDs.Append(cBUUID); var advertisingOption = new StartAdvertisingOptions { LocalName = "RemoteX Controller" }; advertisingOption.ServicesUUID = cBUUIDs; cBPeripheralManager.StartAdvertising(advertisingOption); }
public override void ViewDidLoad () { base.ViewDidLoad (); beaconUUID = new NSUuid (uuid); beaconRegion = new CLBeaconRegion (beaconUUID, beaconMajor, beaconMinor, beaconId); //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away var power = new NSNumber (-59); NSMutableDictionary peripheralData = beaconRegion.GetPeripheralData (power); peripheralDelegate = new BTPeripheralDelegate (); peripheralMgr = new CBPeripheralManager (peripheralDelegate, DispatchQueue.DefaultGlobalQueue); peripheralMgr.StartAdvertising (peripheralData); }
void HandleTouchDown(object sender, EventArgs e) { if (segBeacon.SelectedSegment == 0) { var power = new NSNumber (-59); NSMutableDictionary peripheralData = bRegion.GetPeripheralData (power); pDelegate = new BTPDelegate (); pManager = new CBPeripheralManager (pDelegate, DispatchQueue.DefaultGlobalQueue); pManager.StartAdvertising (peripheralData); } else { locManager = new CLLocationManager (); locManager.RegionEntered += (object s, CLRegionEventArgs ea) => { if (ea.Region.Identifier == "beacon") { UILocalNotification notification = new UILocalNotification () { AlertBody = "Entering beacon region!" }; UIApplication.SharedApplication.PresentLocationNotificationNow (notification); } }; locManager.DidRangeBeacons += (object s, CLRegionBeaconsRangedEventArgs ea) => { if (ea.Beacons.Length > 0) { CLBeacon beacon = ea.Beacons [0]; switch (beacon.Proximity) { case CLProximity.Immediate: this.View.BackgroundColor = UIColor.Green; break; case CLProximity.Near: this.View.BackgroundColor = UIColor.Yellow; break; case CLProximity.Far: this.View.BackgroundColor = UIColor.Red; break; case CLProximity.Unknown: this.View.BackgroundColor = UIColor.Black; break; } } }; locManager.StartMonitoring (bRegion); locManager.StartRangingBeacons (bRegion); } }
public override void ViewDidLoad() { base.ViewDidLoad (); var uuid = new NSUuid ("A1F30FF0-0A9F-4DE0-90DA-95F88164942E"); var beaconId = "iOSBeacon"; var beaconRegion = new CLBeaconRegion (uuid, beaconId) { NotifyEntryStateOnDisplay = true, NotifyOnEntry = true, NotifyOnExit = true }; var peripheralData = beaconRegion.GetPeripheralData (new NSNumber (-59)); peripheralDelegate = new BTPeripheralDelegate (); peripheralMgr = new CBPeripheralManager (peripheralDelegate, DispatchQueue.DefaultGlobalQueue); peripheralMgr.StartAdvertising (peripheralData); }
public FindTheMonkeyViewController() : base(UserInterfaceIdiomIsPhone ? "FindTheMonkeyViewController_iPhone" : "FindTheMonkeyViewController_iPad", null) { peripheralDelegate = new BTPeripheralDelegate (); peripheralMgr = new CBPeripheralManager (peripheralDelegate, DispatchQueue.DefaultGlobalQueue); }
public override void StateUpdated (CBPeripheralManager peripheral) { }
public override void StateUpdated (CBPeripheralManager peripheral) { if (StateUpdatedEvent != null) StateUpdatedEvent (peripheral); }
public void PublishServices(CBPeripheralManager peripheralManager, CBMutableService service) { peripheralManager.AddService(service); }
public override void StateUpdated(CBPeripheralManager peripheral) { Console.WriteLine("State updated: " + peripheral.State); }
public void UpdateSubscribers(CBPeripheralManager peripheralManager, CBMutableCharacteristic characteristic) { peripheralManager.UpdateValue(null, characteristic, characteristic.SubscribedCentrals); }
public override void StateUpdated (CBPeripheralManager peripheral) { if (peripheral.State == CBPeripheralManagerState.PoweredOn) { Console.WriteLine ("powered on"); } }
public override void ViewDidLoad() { base.ViewDidLoad (); var monkeyUUID = new NSUuid (uuid); var beaconRegion = new CLBeaconRegion (monkeyUUID, monkeyId); beaconRegion.NotifyEntryStateOnDisplay = true; beaconRegion.NotifyOnEntry = true; beaconRegion.NotifyOnExit = true; if (!UserInterfaceIdiomIsPhone) { //power - the received signal strength indicator (RSSI) value (measured in decibels) of the beacon from one meter away var power = new NSNumber (-59); NSMutableDictionary peripheralData = beaconRegion.GetPeripheralData (power); peripheralDelegate = new BTPeripheralDelegate (); peripheralMgr = new CBPeripheralManager (peripheralDelegate, DispatchQueue.DefaultGlobalQueue); peripheralMgr.StartAdvertising (peripheralData); } else { InitPitchAndVolume (); locationMgr = new CLLocationManager (); locationMgr.RegionEntered += (object sender, CLRegionEventArgs e) => { if (e.Region.Identifier == monkeyId) { UILocalNotification notification = new UILocalNotification () { AlertBody = "There's a monkey hiding nearby!" }; UIApplication.SharedApplication.PresentLocationNotificationNow (notification); } }; locationMgr.DidRangeBeacons += (object sender, CLRegionBeaconsRangedEventArgs e) => { if (e.Beacons.Length > 0) { CLBeacon beacon = e.Beacons [0]; string message = ""; switch (beacon.Proximity) { case CLProximity.Immediate: message = "You found the monkey!"; monkeyStatusLabel.Text = message; View.BackgroundColor = UIColor.Green; break; case CLProximity.Near: message = "You're getting warmer"; monkeyStatusLabel.Text = message; View.BackgroundColor = UIColor.Yellow; break; case CLProximity.Far: message = "You're freezing cold"; monkeyStatusLabel.Text = message; View.BackgroundColor = UIColor.Blue; break; case CLProximity.Unknown: message = "I'm not sure how close you are to the monkey";; monkeyStatusLabel.Text = message; View.BackgroundColor = UIColor.Gray; break; } if(previousProximity != beacon.Proximity){ Speak (message); } previousProximity = beacon.Proximity; } }; locationMgr.StartMonitoring (beaconRegion); locationMgr.StartRangingBeacons (beaconRegion); } }
public BeaconBroadcasterViewController(IntPtr handle) : base(handle) { _peripheralManager = new CBPeripheralManager(new PeripheralDelegate(), DispatchQueue.DefaultGlobalQueue); _beaconRegion = new CLBeaconRegion(new NSUuid("1EBE566A-56A0-4EEC-80A7-8BB73D4CDE5F"), "iOS Beacon"); }
public void AdvertisingStarted(CBPeripheralManager peripheral) { //TODO something here }
public void StateUpdated(CBPeripheralManager peripheral) { if (peripheral.State == CBPeripheralManagerState.PoweredOn) { } }
static void PeripheralDelegate_StateUpdatedEvent(CBPeripheralManager peripheral) { peripheralDelegate.StateUpdatedEvent -= PeripheralDelegate_StateUpdatedEvent; if (peripheralManager.State < CBPeripheralManagerState.PoweredOn) { Global.ShowNotification (Plugin.Toasts.ToastNotificationType.Error, "iBeacon", "Bluetooth must be enabled."); } else { if (peripheralManager.State == CBPeripheralManagerState.PoweredOn) { StartMonitoring (); } else { Global.ShowNotification (Plugin.Toasts.ToastNotificationType.Error, "iBeacon", "State: " + peripheralManager.State); } } }
public BluetoothServerRequesthandler(CBPeripheralManager manager) { manager.WriteRequestsReceived += OnWriteRequestsReceived; }
public override void DidUpdateState(CBPeripheralManager peripheral) { parent.PeripheralManagerDidUpdateState(); }
public BeaconController() : base("BeaconController", null) { peripheralDelegate = new BTPeripheralDelegate (); peripheralManager = new CBPeripheralManager (peripheralDelegate, DispatchQueue.DefaultGlobalQueue); }