react-native-device-info
Advanced tools
Comparing version 1.3.0 to 1.4.0
## Release Notes | ||
### 1.4.0 | ||
* feat: add battery monitoring and detailed power state getter (https://github.com/react-native-community/react-native-device-info/pull/436) | ||
### 1.3.0 | ||
@@ -4,0 +7,0 @@ * feat: Add support for preferred languages function (https://github.com/react-native-community/react-native-device-info/pull/610) |
@@ -45,2 +45,3 @@ /** | ||
deviceType: 'Unknown', | ||
getPowerState: () => Promise.resolve({}) | ||
}; |
@@ -46,2 +46,3 @@ // should be imported this way: | ||
getBatteryLevel: () => Promise<number>; | ||
getPowerState: () => Promise<object>; | ||
isBatteryCharging: () => Promise<boolean>; | ||
@@ -48,0 +49,0 @@ isLandscape: () => boolean; |
@@ -317,2 +317,5 @@ /** | ||
}, | ||
getPowerState: function() { | ||
return RNDeviceInfo.getPowerState(); | ||
}, | ||
isBatteryCharging: function() { | ||
@@ -319,0 +322,0 @@ return RNDeviceInfo.isBatteryCharging(); |
{ | ||
"name": "react-native-device-info", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "Get device information using react-native", | ||
@@ -35,2 +35,7 @@ "main": "deviceinfo.js", | ||
"url": "https://github.com/machour" | ||
}, | ||
{ | ||
"name": "Mike Hardy", | ||
"email": "github@mikehardy.net", | ||
"url": "https://github.com/mikehardy" | ||
} | ||
@@ -37,0 +42,0 @@ ], |
@@ -236,2 +236,3 @@ # react-native-device-info | ||
| [getPhoneNumber()](#getphonenumber) | `string` | ❌ | ✅ | ❌ | 0.12.0 | | ||
| [getPowerState()](#getpowerstate) | `Promise<object>` | ✅ | ❌ | ❌ | | | ||
| [getReadableVersion()](#getreadableversion) | `string` | ✅ | ✅ | ✅ | ? | | ||
@@ -249,3 +250,3 @@ | [getSerialNumber()](#getserialnumber) | `string` | ❌ | ✅ | ❌ | 0.12.0 | | ||
| [isAirPlaneMode()](#isairplanemode) | `Promise<boolean>` | ❌ | ✅ | ❌ | 0.25.0 | | ||
| [isBatteryCharging()](#isbatterycharging) | `Promise<boolean>` | ❌ | ✅ | ❌ | 0.27.0 | | ||
| [isBatteryCharging()](#isbatterycharging) | `Promise<boolean>` | ✅ | ✅ | ❌ | 0.27.0 | | ||
| [isEmulator()](#isemulator) | `boolean` | ✅ | ✅ | ✅ | ? | | ||
@@ -674,2 +675,21 @@ | [isPinOrFingerprintSet()](#ispinorfingerprintset) | (callback)`boolean` | ✅ | ✅ | ✅ | 0.10.1 | | ||
### getPowerState() | ||
Gets the power state of the device including the battery level, whether it is plugged in, and if the system is currently operating in low power mode. | ||
Displays a warning on iOS if battery monitoring not enabled, or if attempted on an emulator (where monitoring is not possible) | ||
**Examples** | ||
```js | ||
DeviceInfo.getPowerState().then(state => { | ||
// { | ||
// batteryLevel: 0.759999, | ||
// batteryState: 'unplugged', | ||
// lowPowerMode: false, | ||
// } | ||
}); | ||
``` | ||
--- | ||
### getReadableVersion() | ||
@@ -987,2 +1007,55 @@ | ||
## Events | ||
Currently iOS-only. | ||
### batteryLevelDidChange | ||
Fired when the battery level changes; sent no more frequently than once per minute. | ||
**Examples** | ||
```js | ||
import { NativeEventEmitter, NativeModules } from 'react-native' | ||
const deviceInfoEmitter = new NativeEventEmitter(NativeModules.RNDeviceInfo) | ||
deviceInfoEmitter.addListener('batteryLevelDidChange', level => { | ||
// 0.759999 | ||
}); | ||
``` | ||
--- | ||
### batteryLevelIsLow | ||
Fired when the battery drops below 20%. | ||
**Examples** | ||
```js | ||
import { NativeEventEmitter, NativeModules } from 'react-native' | ||
const deviceInfoEmitter = new NativeEventEmitter(NativeModules.RNDeviceInfo) | ||
deviceInfoEmitter.addListener('batteryLevelIsLow', level => { | ||
// 0.19 | ||
}); | ||
``` | ||
--- | ||
### powerStateDidChange | ||
Fired when the battery state changes, for example when the device enters charging mode or is unplugged. | ||
**Examples** | ||
```js | ||
import { NativeEventEmitter, NativeModules } from 'react-native' | ||
const deviceInfoEmitter = new NativeEventEmitter(NativeModules.RNDeviceInfo) | ||
deviceInfoEmitter.addListener('powerStateDidChange', { batteryState } => { | ||
// 'charging' | ||
}); | ||
``` | ||
## Troubleshooting | ||
@@ -1024,5 +1097,5 @@ | ||
This is a system level log that may be turned off by executing: | ||
```xcrun simctl spawn booted log config --mode "level:off" --subsystem com.apple.CoreTelephony```. | ||
To undo the command, you can execute: | ||
This is a system level log that may be turned off by executing: | ||
```xcrun simctl spawn booted log config --mode "level:off" --subsystem com.apple.CoreTelephony```. | ||
To undo the command, you can execute: | ||
```xcrun simctl spawn booted log config --mode "level:info" --subsystem com.apple.CoreTelephony``` | ||
@@ -1029,0 +1102,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
248642
1174
451