title: How to get battery life of Bluetooth Low Energy in Swift 4?
body: <p>I am able to get a value for BLE battery life with the help of following questions:</p>
  
  <p><a href="https://stackoverflow.com/questions/19928623/read-data-from-ble-device">Read data from BLE device</a></p>
  
  <p><a href="https://stackoverflow.com/questions/32894363/reading-a-ble-peripheral-characteristic-and-checking-its-value" title="Reading a BLE Peripheral Characteristic and checking its value?">Reading a BLE Peripheral Characteristic and checking its value?</a></p>
  
  <p>But I am not sure if It returns the right value? It returns 18, and I am also not sure about the maximum number to determine the battery life based on percentage. Does it mean 18 hours?</p>
  
  <pre><code>func peripheral(_ peripheral: CBPeripheral, didDiscoverCharacteristicsFor service: CBService, error: Error?) {
  
      print("-CBService is: \(service.uuid.description)")
  
      if compare(service.uuid, uuid2: CBUUID(string:BluetoothConstants.TI_KEYFOB_BATT_SERVICE_UUID)) {
          print("Battyer Life determination")
  
          for characteristic: CBCharacteristic in service.characteristics! {
              if characteristic.uuid == CBUUID(string: BluetoothConstants.TI_KEYFOB_LEVEL_SERVICE_UUID) {
                  print(characteristic.properties.rawValue)
              }
          }
      }
  }
  </code></pre>
  
  <p>The following line is print for characterstic:</p>
  
  <pre><code>CBCharacteristic: 0x1c00be8a0, UUID = Battery Level, properties =
  0x12, value = (null), notifying = NO&gt;
  </code></pre>
  
  <p>I tried most of the answers here but they are not working for Swift 4. </p>