How to use react-native-device-info - 10 common examples

To help you get started, we’ve selected a few react-native-device-info examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github zulip / zulip-mobile / src / sentry.js View on Github external
const preventNoise = (): void => {
  /* Sentry should not normally be used in debug mode. (For one thing, the
     debug-mode build process doesn't ordinarily create bundles or .map files,
     so you'll probably get nonsensical stack traces.) */
  if (process.env.NODE_ENV === 'development' && config.sentryKey !== null) {
    /* If you have some reason to initialize Sentry in debug mode anyway, please
       change the app's version name (currently specified in `ios/Info.plist`
       and/or `android/app/build.gradle`) to something that doesn't look like a
       normal version number -- preferably with your name and/or Github ID in
       it. This will allow events produced by these debug builds to be easily
       identified in the Sentry console. */
    if (DeviceInfo.getVersion().match(/^\d+\.\d+\.\d+$/)) {
      throw new Error('Sentry should not be initialized in debug builds');
    }
  }

  /* Jest has no reason to even _try_ to initialize Sentry, even if `sentryKey`
     is `null`. */
  // (See the following links concerning detecting Jest.)
  //   [1] https://jestjs.io/docs/en/24.0/getting-started.html#using-babel
  //   [2] https://stackoverflow.com/a/52231746
  if (process.env.NODE_ENV === 'test' || process.env.JEST_WORKER_ID !== undefined) {
    throw new Error('Sentry must not be initialized during testing!');
  }
};
github lomocoin / lomo-rn-boilerplate / src / utils / Analytics.ts View on Github external
logError(
    moduleName: ModulesNames,
    pageName: string,
    functionName: string,
    error: any,
    extra: { [key: string]: string } = {},
  ) {
    const meta = {
      device: `${DeviceInfo.getModel()}-${DeviceInfo.getSystemVersion()}`,
      ...extra,
    };
    const data = {
      [`${functionName}_error`]: `${JSON.stringify(
        meta,
      )}-${this.serializeObject(error)}`,
    };

    if (__DEV__) {
      // tslint:disable-next-line
      console.log(`${moduleName}_${pageName}_${functionName}_error:`, error);
    }
    Analytics.trackEvent(`${moduleName}_${pageName}`, data);
  }
}
github mongrov / roverz / example / src / app / config.js View on Github external
ModuleConfig.gaTrackingId = 'UA-110176262-1';
    ModuleConfig.init();
    ModuleConfig.setLogo(require('../images/logo.png'));  // eslint-disable-line global-require
    ModuleConfig.setNavLogo(require('../images/logo.png'));  // eslint-disable-line global-require
    ModuleConfig.setFilterRooms([
      'support', 'exceptions',
    ]);

    // set user agent
    let ua = ModuleConfig.appName;
    try {
      // Build user agent string
      ua = `${ModuleConfig.appName} ` +
        `${DeviceInfo.getVersion()}; ${DeviceInfo.getSystemName()}  ` +
        `${DeviceInfo.getSystemVersion()}; ${DeviceInfo.getBrand()} ` +
        `${DeviceInfo.getDeviceId()}`;
    } catch (e) {
      // do nothing
    }
    AppAPI.setUserAgent(ua);
  },
github mongrov / roverz / example / src / app / config.js View on Github external
ModuleConfig.bootstrapUrl = 'roverz.mongrov.com';
    ModuleConfig.gaTrackingId = 'UA-110176262-1';
    ModuleConfig.init();
    ModuleConfig.setLogo(require('../images/logo.png'));  // eslint-disable-line global-require
    ModuleConfig.setNavLogo(require('../images/logo.png'));  // eslint-disable-line global-require
    ModuleConfig.setFilterRooms([
      'support', 'exceptions',
    ]);

    // set user agent
    let ua = ModuleConfig.appName;
    try {
      // Build user agent string
      ua = `${ModuleConfig.appName} ` +
        `${DeviceInfo.getVersion()}; ${DeviceInfo.getSystemName()}  ` +
        `${DeviceInfo.getSystemVersion()}; ${DeviceInfo.getBrand()} ` +
        `${DeviceInfo.getDeviceId()}`;
    } catch (e) {
      // do nothing
    }
    AppAPI.setUserAgent(ua);
  },
github HenryQuan / WoWs-Info-Re / WoWs_Info / src / core / util / Language.js View on Github external
static getCurrentLanguage() {
    // Get current language
    var DeviceInfo = require('react-native-device-info');
    var lang = DeviceInfo.getDeviceLocale();
    if (lang.includes('-')) {
      // Simplify -> ja-US to ja only
      lang = lang.split('-').slice(0, -1);
      // Basic filter
      switch (lang[0]) {
        case 'cs':
        case 'de':
        case 'en':
        case 'es':
        case 'fr':
        case 'ja':
        case 'pl':
        case 'pt':
        case 'ru':
        case 'th':
        case 'tr':
github AllenCoder / ReactNativeNote / app / app / pages / Splash.js View on Github external
componentDidMount() {

        console.log("Device Unique ID", DeviceInfo.getUniqueID());  // e.g. FCDBD8EF-62FC-4ECB-B2F5-92C9E79AC7F9
// * note this is IDFV on iOS so it will change if all apps from the current apps vendor have been previously uninstalled

        console.log("Device Manufacturer", DeviceInfo.getManufacturer());  // e.g. Apple

        console.log("Device Model", DeviceInfo.getModel());  // e.g. iPhone 6

        console.log("Device ID", DeviceInfo.getDeviceId());  // e.g. iPhone7,2 / or the board on Android e.g. goldfish

        console.log("Device Name", DeviceInfo.getSystemName());  // e.g. iPhone OS

        console.log("Device Version", DeviceInfo.getSystemVersion());  // e.g. 9.0

        console.log("Bundle Id", DeviceInfo.getBundleId());  // e.g. com.learnium.mobile

        console.log("Build Number", DeviceInfo.getBuildNumber());  // e.g. 89

        console.log("App Version", DeviceInfo.getVersion());  // e.g. 1.1.0

        console.log("App Version (Readable)", DeviceInfo.getReadableVersion());  // e.g. 1.1.0.89

        console.log("Device Name", DeviceInfo.getDeviceName());  // e.g. Becca's iPhone 6

        console.log("User Agent", DeviceInfo.getUserAgent()); // e.g. Dalvik/2.1.0 (Linux; U; Android 5.1; Google Nexus 4 - 5.1.0 - API 22 - 768x1280 Build/LMY47D)
github mongrov / roverz / example / src / app / config.js View on Github external
ModuleConfig.brand = 'mongrov.com';
    ModuleConfig.bootstrapUrl = 'roverz.mongrov.com';
    ModuleConfig.gaTrackingId = 'UA-110176262-1';
    ModuleConfig.init();
    ModuleConfig.setLogo(require('../images/logo.png'));  // eslint-disable-line global-require
    ModuleConfig.setNavLogo(require('../images/logo.png'));  // eslint-disable-line global-require
    ModuleConfig.setFilterRooms([
      'support', 'exceptions',
    ]);

    // set user agent
    let ua = ModuleConfig.appName;
    try {
      // Build user agent string
      ua = `${ModuleConfig.appName} ` +
        `${DeviceInfo.getVersion()}; ${DeviceInfo.getSystemName()}  ` +
        `${DeviceInfo.getSystemVersion()}; ${DeviceInfo.getBrand()} ` +
        `${DeviceInfo.getDeviceId()}`;
    } catch (e) {
      // do nothing
    }
    AppAPI.setUserAgent(ua);
  },
github AllenCoder / ReactNativeNote / app / app / pages / Splash.js View on Github external
console.log("Device Name", DeviceInfo.getSystemName());  // e.g. iPhone OS

        console.log("Device Version", DeviceInfo.getSystemVersion());  // e.g. 9.0

        console.log("Bundle Id", DeviceInfo.getBundleId());  // e.g. com.learnium.mobile

        console.log("Build Number", DeviceInfo.getBuildNumber());  // e.g. 89

        console.log("App Version", DeviceInfo.getVersion());  // e.g. 1.1.0

        console.log("App Version (Readable)", DeviceInfo.getReadableVersion());  // e.g. 1.1.0.89

        console.log("Device Name", DeviceInfo.getDeviceName());  // e.g. Becca's iPhone 6

        console.log("User Agent", DeviceInfo.getUserAgent()); // e.g. Dalvik/2.1.0 (Linux; U; Android 5.1; Google Nexus 4 - 5.1.0 - API 22 - 768x1280 Build/LMY47D)


        const {navigator} = this.props;
        storge.load({
            key:'AppVersion',
            autoSync:true,
        }).then(ret =>{
            version = ret.AppVersion;
            console.log(JSON.stringify(version))
        }).catch(err => {
            // 如果没有找到数据且没有同步方法,
            // 或者有其他异常,则在catch中返回
            console.warn(err);
        })

        this.timer = setTimeout(()=> {
github NSWSESMembers / availability-poc / client / src / components / push / PushHandler.js View on Github external
if (!pushManager.hasAllTokens) {
      log('Cannot update tokens yet because they are still loading');
      return;
    }

    console.log('Have device and tokens, will compare to stored server answer');

    // this needs to understand what to do with multiple tokens
    const jsonTokens = JSON.stringify(pushManager.tokens);
    log('Server has: ', device.pushToken);
    if (jsonTokens !== device.pushToken) {
      log('Sending tokens to the server: ', jsonTokens);
      this.props.updateDevice({
        token: jsonTokens,
        name: DeviceInfo.getDeviceName(),
      }).then(() => {
        log('Token update was successful');
      }).catch((err) => {
        log('Token update failed: ', err);
      });
    } else {
      log('Not sending tokens to the server');
    }
  }
github JetBrains / youtrack-mobile / src / components / usage / usage.js View on Github external
/* @flow */
import DeviceInfo from 'react-native-device-info';
import {Analytics, Hits as GAHits} from 'react-native-google-analytics';
import appPackage from '../../../package.json'; // eslint-disable-line import/extensions

const splitRegExp = /[\.-]/i;
const VERSION = appPackage.version || 'dev.dev.dev-dev';

const [major, minor, patch, build] = VERSION.split(splitRegExp);
const patchPart = parseInt(patch) === 0 ? '' : `.${patch}`;

export const VERSION_STRING = `${major}.${minor}${patchPart} (build ${build})`;

export const USER_AGENT = `YouTrackMobile/${major}.${minor}${patchPart} (${DeviceInfo.getBrand()} ${DeviceInfo.getSystemName()} ${DeviceInfo.getSystemVersion()})`;

const googleAnalyiticsId = appPackage.config.ANALYTICS_ID;
let isAnalyticsEnabled = false;

const clientId = DeviceInfo.getUniqueID();

const ga = new Analytics(googleAnalyiticsId, clientId, 1, DeviceInfo.getUserAgent());

const usage = {
  init(statisticsEnabled: boolean) {
    isAnalyticsEnabled = statisticsEnabled;
  },

  trackScreenView(screenName: string) {
    if (!isAnalyticsEnabled) {
      return;