DeviceInfo.getUniqueID不是函数

mar*_*ins 9 javascript reactjs react-native

我正在研究的本机反应项目已经使用react-native-device-info.当我尝试添加Android-${DeviceInfo.getUniqueID()}到请求中的标头时,我收到此错误:

  { TypeError: DeviceInfo.getUniqueID is not a function
        at makeRequest (~/code/rn/src/services/api-client.js:46:39)
Run Code Online (Sandbox Code Playgroud)

怎么可能?我在它使用的文件的顶部像这样导入它.

import * as DeviceInfo from 'react-native-device-info';
Run Code Online (Sandbox Code Playgroud)

如果我将import语句更改为import DeviceInfo from 'react-native-device-info';,那么我收到此错误:

TypeError: _reactNativeDeviceInfo2.default.getUniqueID is not a function

export function makeRequest(endpoint, method, token, csrfToken = null, body = null) {
    const config = {
        method,
        credentials: 'same-origin',
        headers: {
            Applikasjon: 'KONSERNAPP',
            Accept: 'application/json',
            'X-App-Version': `Android-${DeviceInfo.getUniqueID()}`,
            'Content-Type': 'application/json',
            token,
        },
        timeout: 120000,
    };
Run Code Online (Sandbox Code Playgroud)

Sob*_*had 6

由于 react-native-device-info 升级到4.x.x它的方法错字有点改变,它现在接受DeviceInfo.getUniqueId()而不是DeviceInfo.getUniqueID()


Gui*_*nco 3

这为我解决了问题, DeviceInfo.getUniqueId() 而不是 DeviceInfo.getUniqueID(). 哈哈。这是文档中的拼写错误