nativescript-dna-deviceinfo
Advanced tools
Comparing version 3.3.1 to 3.4.0
@@ -1,2 +0,2 @@ | ||
import { Carrier, DisplayMetrics, StorageVolume } from './deviceinfo.interface'; | ||
import { Address, Carrier, DisplayMetrics, StorageVolume } from './deviceinfo.interface'; | ||
export declare function staticDecorator<T>(): (constructor: T) => void; | ||
@@ -27,4 +27,5 @@ export declare class DeviceInfo { | ||
static displayMetrics(): DisplayMetrics; | ||
static wifiIpv4Address(): Promise<string>; | ||
static cellularIpv4Address(): Promise<string>; | ||
static wifiIpv4Address(): string; | ||
static cellularIpv4Address(): string; | ||
static dumpIpAddresses(): Address[]; | ||
static isPortrait(): boolean; | ||
@@ -49,2 +50,3 @@ static isTablet(): boolean; | ||
private static ipv4Address; | ||
private static ipAddresses; | ||
} |
var DeviceInfo_1; | ||
import * as application from '@nativescript/core/application'; | ||
import { wirelessCellularGenerator, } from './deviceinfo.interface'; | ||
import { AddressType, wirelessCellularGenerator, } from './deviceinfo.interface'; | ||
import { networkProviderByMcc, networkProviderByMccMnc } from './network-provider'; | ||
@@ -313,7 +313,10 @@ import { round } from "./utility"; | ||
static wifiIpv4Address() { | ||
return DeviceInfo_1.ipv4Address(); | ||
return DeviceInfo_1.ipv4Address("wlan"); | ||
} | ||
static cellularIpv4Address() { | ||
return DeviceInfo_1.ipv4Address(); | ||
return DeviceInfo_1.ipv4Address("rmnet"); | ||
} | ||
static dumpIpAddresses() { | ||
return DeviceInfo_1.ipAddresses(); | ||
} | ||
static isPortrait() { | ||
@@ -547,28 +550,36 @@ const Configuration = android.content.res.Configuration; | ||
} | ||
static ipv4Address() { | ||
return new Promise((resolve, reject) => { | ||
try { | ||
const NetworkInterface = java.net.NetworkInterface; | ||
const Collections = java.util.Collections; | ||
const interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); | ||
for (let index = 0; index < interfaces.size(); index++) { | ||
const netInterface = interfaces.get(index); | ||
const addrs = Collections.list(netInterface.getInetAddresses()); | ||
for (let addrIndex = 0; addrIndex < addrs.size(); addrIndex++) { | ||
const addr = addrs.get(addrIndex); | ||
if (!addr.isLoopbackAddress()) { | ||
const hostAddr = addr.getHostAddress(); | ||
const isIPv4 = hostAddr.indexOf(':') < 0; | ||
if (isIPv4) { | ||
return resolve(hostAddr); | ||
} | ||
} | ||
} | ||
static ipv4Address(interfaceName) { | ||
const addresses = DeviceInfo_1.ipAddresses(); | ||
const foundAddress = addresses.find(addr => { | ||
if (addr.adapterName && addr.adapterName.includes(interfaceName)) { | ||
if (addr.type == AddressType.IPv4) { | ||
return true; | ||
} | ||
} | ||
catch (Exception) { | ||
} | ||
resolve(""); | ||
return false; | ||
}); | ||
return foundAddress ? foundAddress.address : ""; | ||
} | ||
static ipAddresses() { | ||
const NetworkInterface = java.net.NetworkInterface; | ||
const Collections = java.util.Collections; | ||
let addresses = []; | ||
try { | ||
const interfaces = Collections.list(NetworkInterface.getNetworkInterfaces()); | ||
for (let index = 0; index < interfaces.size(); index++) { | ||
const netInterface = interfaces.get(index); | ||
const displayName = netInterface.getDisplayName(); | ||
const addrs = Collections.list(netInterface.getInetAddresses()); | ||
for (let addrIndex = 0; addrIndex < addrs.size(); addrIndex++) { | ||
const addr = addrs.get(addrIndex); | ||
const hostAddr = addr.getHostAddress(); | ||
const addrType = hostAddr.indexOf(':') < 0 ? AddressType.IPv4 : AddressType.IPv6; | ||
addresses.push({ address: hostAddr, type: addrType, adapterName: displayName }); | ||
} | ||
} | ||
} | ||
catch (Exception) { | ||
} | ||
return addresses; | ||
} | ||
}; | ||
@@ -575,0 +586,0 @@ DeviceInfo = DeviceInfo_1 = __decorate([ |
@@ -89,4 +89,5 @@ export declare const enum RadioAccessTechnology { | ||
displayMetrics(): DisplayMetrics; | ||
wifiIpv4Address(): Promise<string>; | ||
cellularIpv4Address(): Promise<string>; | ||
wifiIpv4Address(): string; | ||
cellularIpv4Address(): string; | ||
dumpIpAddresses(): Address[]; | ||
isPortrait(): boolean; | ||
@@ -93,0 +94,0 @@ isTablet(): boolean; |
@@ -1,2 +0,2 @@ | ||
import { Carrier, DisplayMetrics, StorageVolume } from './deviceinfo.interface'; | ||
import { Address, Carrier, DisplayMetrics, StorageVolume } from './deviceinfo.interface'; | ||
export declare function staticDecorator<T>(): (constructor: T) => void; | ||
@@ -29,4 +29,5 @@ export declare class DeviceInfo { | ||
static displayMetrics(): DisplayMetrics; | ||
static wifiIpv4Address(): Promise<string>; | ||
static cellularIpv4Address(): Promise<string>; | ||
static wifiIpv4Address(): string; | ||
static cellularIpv4Address(): string; | ||
static dumpIpAddresses(): Address[]; | ||
static isPortrait(): boolean; | ||
@@ -33,0 +34,0 @@ static isTablet(): boolean; |
@@ -221,19 +221,18 @@ var DeviceInfo_1; | ||
static wifiIpv4Address() { | ||
return new Promise((resolve, reject) => { | ||
const iPhoneWifiInterfaceName = "en0"; | ||
const appleTvWifiInterfaceName = "en1"; | ||
let addresses = DeviceInfo_1.getInterfaceCardIpAddress(iPhoneWifiInterfaceName, AddressType.IPv4); | ||
if (addresses.length === 0 || addresses[0].address === "") { | ||
addresses = DeviceInfo_1.getInterfaceCardIpAddress(appleTvWifiInterfaceName, AddressType.IPv4); | ||
} | ||
return resolve(addresses.length ? addresses[0].address : ""); | ||
}); | ||
const iPhoneWifiInterfaceName = "en0"; | ||
const appleTvWifiInterfaceName = "en1"; | ||
let addresses = DeviceInfo_1.getInterfaceCardIpAddress(iPhoneWifiInterfaceName, AddressType.IPv4); | ||
if (addresses.length === 0 || addresses[0].address === "") { | ||
addresses = DeviceInfo_1.getInterfaceCardIpAddress(appleTvWifiInterfaceName, AddressType.IPv4); | ||
} | ||
return addresses.length ? addresses[0].address : ""; | ||
} | ||
static cellularIpv4Address() { | ||
return new Promise((resolve, reject) => { | ||
const iPhonePhoneDataServiceInterfaceName = "pdp_ip0"; | ||
let addresses = DeviceInfo_1.getInterfaceCardIpAddress(iPhonePhoneDataServiceInterfaceName, AddressType.IPv4); | ||
return resolve(addresses.length ? addresses[0].address : ""); | ||
}); | ||
const iPhonePhoneDataServiceInterfaceName = "pdp_ip0"; | ||
let addresses = DeviceInfo_1.getInterfaceCardIpAddress(iPhonePhoneDataServiceInterfaceName, AddressType.IPv4); | ||
return addresses.length ? addresses[0].address : ""; | ||
} | ||
static dumpIpAddresses() { | ||
return DeviceInfo_1.getInterfaceCardIpAddress(); | ||
} | ||
static isPortrait() { | ||
@@ -240,0 +239,0 @@ return UIDevice.currentDevice.orientation === 1 || |
@@ -29,4 +29,5 @@ import { Carrier, StorageVolume, DisplayMetrics, RadioAccessTechnology, WCTGeneration } from './deviceinfo.interface'; | ||
static displayMetrics(): DisplayMetrics; | ||
static wifiIpv4Address(): Promise<string>; | ||
static cellularIpv4Address(): Promise<string>; | ||
static wifiIpv4Address(): string; | ||
static cellularIpv4Address(): string; | ||
static dumpIpAddresses(): Address[] | ||
static isPortrait(): boolean; | ||
@@ -33,0 +34,0 @@ static isTablet(): boolean; |
{ | ||
"name": "nativescript-dna-deviceinfo", | ||
"version": "3.3.1", | ||
"version": "3.4.0", | ||
"description": "NativeScript plugin to acquire device information.", | ||
@@ -5,0 +5,0 @@ "main": "deviceinfo", |
165
README.md
@@ -10,7 +10,8 @@ | ||
Kindly visit [typescript demo](https://github.com/DeepakArora76/nativescript-dna-deviceinfo/tree/master/demo) or [js demo](https://github.com/DeepakArora76/NativescriptDeviceInfoJSDemo.git) repository for practical implementation guidance and hints. | ||
Kindly visit [typescript demo](https://github.com/DeepakArora76/nativescript-dna-deviceinfo/tree/master/demo) or [js demo](https://github.com/DeepakArora76/JSDeviceInfoDemo.git) repository for practical implementation guidance and hints. | ||
## Changelogs: | ||
- 3.3.1: Fix a crash related to the retrieval of wifi SSID on iOS 13.0 version and above. | ||
- 3.4.0: Added "dumpIpAddresses" API. Changed "wifiIpv4Address" and "cellularIpv4Address" to return an IPv4 address string, and their Android implementation is revised. | ||
- 3.3.1: Fixed a crash related to the retrieval of wifi SSID on iOS 13.0 version and above. | ||
- 3.3.0: Added "wifiIpv4Address" and "cellularIpv4Address" APIs for iOS and Android. Fixed issues related to Bluetooth detection for Android. | ||
@@ -55,7 +56,7 @@ - 3.2.1: Updated Apple's mobile device codes types a.k.a. machine ids (e.g. `iPhone1,1`, `Watch1,1`, etc.) and their matching product names. | ||
Various device related utility APIs are accessible from the DeviceInfo class. To import the class, use one of the following forms: | ||
Various device-related APIs are accessible from the DeviceInfo class. To import the class, use one of the following forms: | ||
TypeScript: | ||
```javascript | ||
import { DeviceInfo } from 'nativescript-dna-deviceinfo'; | ||
import { DeviceInfo } from "nativescript-dna-deviceinfo"; | ||
``` | ||
@@ -70,41 +71,45 @@ JavaScript: | ||
## APIs | ||
Below is the list of APIs with their supported platforms. Kindly visit [typescript demo](https://github.com/DeepakArora76/nativescript-dna-deviceinfo/tree/master/demo) or [js demo](https://github.com/DeepakArora76/NativescriptDeviceInfoJSDemo.git) repository for practical implementation guidance and hints. | ||
Below is the list of APIs with their supported platforms. | ||
| API | Return Type | iOS | Android | | ||
| -------------------------------| -----------------------|:-----:|:---------:| | ||
| totalMemory | number | + | + | | ||
| freeMemory | number | + | + | | ||
| totalStorageSpace | number | + | + | | ||
| freeStorageSpace | number | + | + | | ||
| deviceId | string | + | + | | ||
| deviceName | string | + | + | | ||
| deviceLocale | string | + | + | | ||
| deviceCountry | string | + | + | | ||
| timezone | string | + | + | | ||
| userAgent | Promise<string> | + | + | | ||
| appName | string | + | + | | ||
| appVersion | string | + | + | | ||
| bundleId | string | + | + | | ||
| bundleNumber | string | + | - | | ||
| systemManufacturer | string | + | + | | ||
| batteryLevel | number | + | + | | ||
| cellularServiceProviders | Carrier[] | + | + | | ||
| externalStoragePaths | string[] | - | + | | ||
| storageVolumes | StorageVolume[] | - | + | | ||
| wifiSSID | string | + | + | | ||
| displayMetrics | DisplayMetrics | + | + | | ||
| wifiIpv4Address | Promise<string> | + | + | | ||
| cellularIpv4Address | Promise<string> | + | + | | ||
| isPortrait | boolean | + | + | | ||
| isTablet | boolean | + | + | | ||
| is24Hour | boolean | + | + | | ||
| isEmulator | boolean | + | + | | ||
| isBatteryCharging | boolean | + | + | | ||
| isLocationEnabled | Promise<boolean> | + | + | | ||
| isBluetoothEnabled | Promise<boolean> | + | + | | ||
Kindly visit [typescript demo](https://github.com/DeepakArora76/nativescript-dna-deviceinfo/tree/master/demo) or [js demo](https://github.com/DeepakArora76/JSDeviceInfoDemo.git) repository for practical implementation guidance and hints. | ||
Description of the APIs: | ||
| API | Return Type | iOS | Android | | ||
| ------------------------------------------------------| -----------------------|:-----:|:---------:| | ||
| [totalMemory](#totalMemory) | number | + | + | | ||
| [freeMemory](#freeMemory) | number | + | + | | ||
| [totalStorageSpace](#totalStorageSpace) | number | + | + | | ||
| [freeStorageSpace](#freeStorageSpace) | number | + | + | | ||
| [deviceId](#deviceId) | string | + | + | | ||
| [deviceName](#deviceName) | string | + | + | | ||
| [deviceLocale](#deviceLocale) | string | + | + | | ||
| [deviceCountry](#deviceCountry) | string | + | + | | ||
| [timezone](#timezone) | string | + | + | | ||
| [userAgent](#userAgent) | Promise<string> | + | + | | ||
| [appName](#appName) | string | + | + | | ||
| [appVersion](#appVersion) | string | + | + | | ||
| [bundleId](#bundleId) | string | + | + | | ||
| [bundleNumber](#bundleNumber) | string | + | - | | ||
| [systemManufacturer](#systemManufacturer) | string | + | + | | ||
| [batteryLevel](#batteryLevel) | number | + | + | | ||
| [cellularServiceProviders](#cellularServiceProviders) | Carrier[] | + | + | | ||
| [externalStoragePaths](#externalStoragePaths) | string[] | - | + | | ||
| [storageVolumes](#storageVolumes) | StorageVolume[] | - | + | | ||
| [wifiSSID](#wifiSSID) | string | + | + | | ||
| [displayMetrics](#displayMetrics) | DisplayMetrics | + | + | | ||
| [wifiIpv4Address](#wifiIpv4Address) | string | + | + | | ||
| [cellularIpv4Address](#cellularIpv4Address) | string | + | + | | ||
| [dumpIpAddresses](#dumpIpAddresses) | Address[] | + | + | | ||
| [isPortrait](#isPortrait) | boolean | + | + | | ||
| [isTablet](#isTablet) | boolean | + | + | | ||
| [is24Hour](#is24Hour) | boolean | + | + | | ||
| [isEmulator](#isEmulator) | boolean | + | + | | ||
| [isBatteryCharging](#isBatteryCharging) | boolean | + | + | | ||
| [isLocationEnabled](#isLocationEnabled) | Promise<boolean> | + | + | | ||
| [isBluetoothEnabled](#isBluetoothEnabled) | Promise<boolean> | + | + | | ||
### - totalMemory | ||
Each of the above APIs is described in detail along with their platform requirements where it makes sense. | ||
### totalMemory | ||
Returns total memory(RAM) size of a device in bytes. | ||
@@ -116,3 +121,3 @@ | ||
### - freeMemory | ||
### freeMemory | ||
@@ -125,3 +130,3 @@ Returns free memory(RAM) size of a device in bytes. | ||
### - totalStorageSpace | ||
### totalStorageSpace | ||
@@ -134,3 +139,3 @@ Returns total storage(internal) space of a device in bytes. | ||
### - freeStorageSpace | ||
### freeStorageSpace | ||
@@ -143,3 +148,3 @@ Returns free storage(internal) space of a device in bytes. | ||
### - deviceId | ||
### deviceId | ||
@@ -152,3 +157,3 @@ Returns a device ID. | ||
### - deviceName | ||
### deviceName | ||
@@ -164,3 +169,3 @@ Returns a device name. | ||
### - deviceLocale | ||
### deviceLocale | ||
@@ -173,3 +178,3 @@ Returns the locale of a device. | ||
### - deviceCountry | ||
### deviceCountry | ||
@@ -182,3 +187,3 @@ Returns the device country. | ||
### - timezone | ||
### timezone | ||
@@ -191,3 +196,3 @@ Returns the time zone of a device. | ||
### - userAgent | ||
### userAgent | ||
@@ -200,3 +205,3 @@ Returns Promise which resolves to 'user agent' if fetched successfully, otherwise 'error'. | ||
### - appName | ||
### appName | ||
@@ -209,3 +214,3 @@ Returns an app name. | ||
### - appVersion | ||
### appVersion | ||
@@ -218,3 +223,3 @@ Returns an app version. | ||
### - bundleId | ||
### bundleId | ||
@@ -227,3 +232,3 @@ Returns an app bundle id. | ||
### - bundleNumber | ||
### bundleNumber | ||
@@ -236,3 +241,3 @@ Returns an app bundle number. | ||
### - systemManufacturer | ||
### systemManufacturer | ||
@@ -245,3 +250,3 @@ Returns a device manufacturer. | ||
### - batteryLevel | ||
### batteryLevel | ||
@@ -254,3 +259,3 @@ Returns the charge level of a device battery. | ||
### - cellularServiceProviders | ||
### cellularServiceProviders | ||
@@ -286,3 +291,3 @@ Returns a list of GSM network providers, *Carrier*, in use by device. In absence of adequate permission, returns empty *Carrier* list. | ||
### - externalStoragePaths | ||
### externalStoragePaths | ||
@@ -295,3 +300,3 @@ Returns a list of paths for all mountable volumes (external storage cards, USB O-T-G). The empty list means that no mountable volumes found. | ||
### - storageVolumes | ||
### storageVolumes | ||
@@ -322,3 +327,3 @@ Returns a list of *StorageVolume*. An empty list means that no mountable volumes found. | ||
### - wifiSSID | ||
### wifiSSID | ||
@@ -331,6 +336,2 @@ Returns service set identifier(SSID) of a wireless local area network (WLAN). In absence of right permissions, returns an empty string. | ||
- Notes for iOS users: | ||
* Supported on iOS 12.0 and older versions. | ||
* Version above 12.0 uses NEHotspotHelper which requires "com.apple.developer.networking.HotspotHelper" entitlement by Apple. | ||
- Notes for Android users: | ||
@@ -342,4 +343,5 @@ * Permissions ACCESS_WIFI_STATE and ACCESS_FINE_LOCATION/ACCESS_COARSE_LOCATION are required. | ||
- Notes for iOS users: | ||
* To use this API on iOS 12 and later, enable the Access WiFi Information. | ||
* To use this API on iOS 13 and later, enable the Access WiFi Information, and | ||
* To use this API on iOS 12 and earlier, enable the Access WiFi Information. | ||
* The API for iOS 13 and above uses NEHotspotHelper which requires "com.apple.developer.networking.HotspotHelper" entitlement by Apple. | ||
* To use this API on iOS 13 and above, enable the Access WiFi Information, and | ||
* must also meet at least one of criteria below | ||
@@ -367,3 +369,3 @@ * Apps with permission to access location | ||
### - displayMetrics | ||
### displayMetrics | ||
@@ -391,5 +393,5 @@ Returns *DisplayMetrics* of a device. | ||
### - wifiIpv4Address | ||
### wifiIpv4Address | ||
Returns *Promise<string>* which resolves to WiFi IPv4 address. | ||
Returns WiFi IPv4 address. | ||
@@ -403,5 +405,5 @@ ```javascript | ||
### - cellularIpv4Address | ||
### cellularIpv4Address | ||
Returns *Promise<string>* which resolves to cellular IPv4 address. | ||
Returns cellular IPv4 address. | ||
@@ -415,3 +417,14 @@ ```javascript | ||
### - isPortrait | ||
### dumpIpAddresses | ||
Returns *Address[]*, which is a collection of IPv4 and IPv6 addresses that a device is equipped with. | ||
```javascript | ||
DeviceInfo.dumpIpAddresses(); | ||
``` | ||
- Notes for Android users: | ||
* Make sure that the permissions *android.permission.INTERNET*, *android.permission.ACCESS_NETWORK_STATE*, and *android.permission.ACCESS_WIFI_STATE* are in place in AndroidManifest.xml and in code too. | ||
### isPortrait | ||
Returns 'true' if a device is in portrait mode, otherwise 'false'. | ||
@@ -423,3 +436,3 @@ | ||
### - isTablet | ||
### isTablet | ||
@@ -432,3 +445,3 @@ Returns 'true' if a device is a tablet, otherwise 'false'. | ||
### - is24Hour | ||
### is24Hour | ||
@@ -441,3 +454,3 @@ Returns 'true' if a device configured to a 24-hour clock, otherwise 'false'. | ||
### - isEmulator | ||
### isEmulator | ||
@@ -450,3 +463,3 @@ Returns 'true' if an app is running on an emulator, otherwise 'false'. | ||
### - isBatteryCharging | ||
### isBatteryCharging | ||
@@ -459,3 +472,3 @@ Returns 'true' if a device is plugged in and charging, otherwise 'false'. | ||
### - isLocationEnabled | ||
### isLocationEnabled | ||
@@ -480,3 +493,3 @@ Depending on the state of Location Service and the app permission, returned Promise may resolve to 'true' or 'false'. In the absence of appropriate permission, rejected Promise is returned. | ||
### - isBluetoothEnabled | ||
### isBluetoothEnabled | ||
@@ -483,0 +496,0 @@ Depending on the state of Bluetooth and the app permission, returned Promise may resolve to 'true' or 'false'. In the absence of appropriate permission, rejected Promise is returned. |
400997
15567
533