Ejemplo n.º 1
0
 public void Dispose()
 {
     if (_PeripheralManager == null)
     {
         return;
     }
     _PeripheralManager.Dispose();
     _PeripheralManager = null;
 }
        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);
            }
        }
Ejemplo n.º 3
0
 public void Dispose()
 {
     if (_Disposed)
     {
         return;
     }
     //  cleanup resources
     if (_PeripheralManager != null)
     {
         _PeripheralManager.Dispose();
     }
     _Disposed = true;
 }