0.4.0 • Published 4 years ago

@react-cross/react-native v0.4.0

Weekly downloads
7
License
MIT
Repository
-
Last release
4 years ago

@react-cross/react-native

npm version npm total downloads npm monthly downloads npm weekly downloads

React Native module for both mobile and web

TOC

Installation

using yarn:

yarn add @react-cross/react-native

web additions

yarn add react-native-web

Linking

react-native link @react-native-community/async-storage
react-native link @react-native-community/netinfo

Usage

import DeviceInfo from 'react-native-device-info';

API

MethodReturn Type iOSAndroidWindowsSince
getAPILevel()number0.12.0
getApplicationName()string0.14.0
getBatteryLevel()Promise<number>0.18.0
getBrand()string0.9.3
getBuildNumber()string?

getAPILevel()

Gets the API level.

Examples

const apiLevel = DeviceInfo.getAPILevel();

// iOS: ?
// Android: 25
// Windows: ?

Notes

See API Levels


getApplicationName()

Gets the application name.

Examples

const appName = DeviceInfo.getApplicationName(); // "Learnium Mobile"

getBatteryLevel()

Gets the battery level of the device as a float comprised between 0 and 1.

Examples

DeviceInfo.getBatteryLevel().then(batteryLevel => {
  // 0.759999
});

Notes

To be able to get actual battery level enable battery monitoring mode for application. Add this code:

[UIDevice currentDevice].batteryMonitoringEnabled = true;

to AppDelegate.m application:didFinishLaunchingWithOptions:

Returns -1 on the iOS Simulator


getBrand()

Gets the device brand.

Examples

const brand = DeviceInfo.getBrand();

// iOS: "Apple"
// Android: "Xiaomi"
// Windows: ?

getBuildNumber()

Gets the application build number.

Examples

const buildNumber = DeviceInfo.getBuildNumber();

// iOS: "89"
// Android: 4
// Windows: ?

Notes

There is a type inconsistency: Android return an integer instead of the documented string.


Troubleshooting

When installing or using react-native-device-info, you may encounter the following problems:

react-native-device-info uses com.google.android.gms:play-services-gcm to provide getInstance(). This can lead to conflicts when building the Android application.

If you're using a different version of com.google.android.gms:play-services-gcm in your app, you can define the googlePlayServicesVersion gradle variable in your build.gradle file to tell react-native-device-info what version it should require. See the example project included here for a sample.

If you're using a different library that conflicts with com.google.android.gms:play-services-gcm, and you are certain you know what you are doing such that you will avoid version conflicts, you can simply ignore this dependency in your gradle file:

 compile(project(':react-native-device-info')) {
    exclude group: 'com.google.android.gms'
}

Seems to be a bug caused by react-native link. You can manually delete libRNDeviceInfo-tvOS.a in Xcode -> [Your iOS build target] -> Build Phrases -> Link Binary with Libraries.

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

Release Notes

See the CHANGELOG.md.

Contributing

Please see the contributing guide.