youngjuning / issues

一寸欢喜 - 怕什么真理无穷,进一寸有一寸的欢喜
https://youngjuning.js.org
44 stars 4 forks source link

react-native-device-info #169

Open youngjuning opened 5 years ago

youngjuning commented 5 years ago
import DeviceInfo from 'react-native-device-info'

const getDeviceInfo = () => ({
  apiLeavel: DeviceInfo.getAPILevel(),
  appName: DeviceInfo.getApplicationName(),
  brand: DeviceInfo.getBrand(),
  buildNumber: DeviceInfo.getBuildNumber(),
  bundleId: DeviceInfo.getBundleId(),
  deviceCountry: DeviceInfo.getDeviceCountry(),
  deviceId: DeviceInfo.getDeviceId(),
  deviceLocale: DeviceInfo.getDeviceLocale(),
  deviceName: DeviceInfo.getDeviceName(),
  firstInstallTime: DeviceInfo.getFirstInstallTime(),
  freeDiskStorage: DeviceInfo.getFreeDiskStorage(),
  referrer: DeviceInfo.getInstallReferrer(),
  instanceId: DeviceInfo.getInstanceID(),
  lastUpdateTime: DeviceInfo.getLastUpdateTime(),
  manufacturer: DeviceInfo.getManufacturer(),
  maxMemory: DeviceInfo.getMaxMemory(),
  model: DeviceInfo.getModel(),
  phoneNumber: DeviceInfo.getPhoneNumber(), // 权限http://t.cn/EP3kKhY
  readableVersion: DeviceInfo.getReadableVersion(),
  serialNumber: DeviceInfo.getSerialNumber(),
  systemName: DeviceInfo.getSystemName(),
  systemVersion: DeviceInfo.getSystemVersion(),
  timezone: DeviceInfo.getTimezone(),
  storageSize: DeviceInfo.getTotalDiskCapacity(),
  totalMemory: DeviceInfo.getTotalMemory(),
  uniqueId: DeviceInfo.getUniqueID(),
  userAgent: DeviceInfo.getUserAgent(),
  version: DeviceInfo.getVersion(),
  is24Hour: DeviceInfo.is24Hour(),
  isEmulator: DeviceInfo.isEmulator(),
  isTablet: DeviceInfo.isTablet(),
})
export default getDeviceInfo
youngjuning commented 5 years ago
import { action, observable } from 'mobx'
import { AppState, NetInfo } from 'react-native'
import AV from 'leancloud-storage'
import { getDeviceInfo } from '../utils'

class AppStore {
  @observable appState = AppState.currentState

  @action handleAppStateChange = (nextAppState) => {
    this.appState = nextAppState
    if (nextAppState === 'background' || nextAppState === 'inactive') {
      console.log('程序进入后台')
      NetInfo.isConnected.fetch().then((isConnected) => {
        console.log(`First, is ${isConnected ? 'online' : 'offline'}`)
        if (isConnected) {
          new AV.Object('CrashLog').save({
            deviceInfo: getDeviceInfo(),
            isDev: __DEV__,
          }).then((res) => {
            // 保存成功
            console.log(res)
          }, (err) => {
            console.warn(err)
          })
        }
      })
    } else {
      console.log('程序进入前台')
    }
  }
}

export default new AppStore()
youngjuning commented 5 years ago

// AppState.addEventListener('change', appStore.handleAppStateChange)

youngjuning commented 5 years ago

// AppState.removeEventListener('change', appStore.handleAppStateChange)

youngjuning commented 5 years ago

AppState/