REACT NATIVE:有办法识别设备类型(智能手机、平板电脑、笔记本电脑)吗?

shi*_*ira 0 javascript api reactjs react-native expo

有办法识别设备类型(智能手机、平板电脑、笔记本电脑)吗?我需要将设备类型识别为:智能手机、平板电脑、笔记本电脑。我尝试使用“react-native-device-info” api 库,但不明白如何识别 3 种特定设备类型(智能手机、平板电脑、笔记本电脑) 。

那么我该如何做一些代码来告诉我如果它的“手机”=>智能手机,如果它的“未知”=>笔记本电脑/计算机,并且它也会保存在我的异步存储中。

import DeviceInfo from 'react-native-device-info';
import AsyncStorage from '@react-native-community/async-storage';

// how can i do some code that will gives me if its "Handset"=> Smartphone , 
//if its "unknown"=> Laptop/Computer 
//and it will be saved as well in my async-storage.

//this some example that i wanna get it works well coz now its not work good

const funct1=  (type) => {
let type = DeviceInfo.getDeviceType();

if type==='Handset'{
  AsyncStorage.setItem('PLATFORM-TYPE', 'Smartphone');
}
if type==='unknown'{
  AsyncStorage.setItem('PLATFORM-TYPE', 'Laptop/Computer');
}
};
Run Code Online (Sandbox Code Playgroud)

Mic*_*bov 5

在提到的react-native-device-info有一个方法getDeviceType()返回

  • Handset对于智能手机,
  • Tablet对于平板电脑,
  • Tv对于电视和
  • unknown对于其他一切(很可能是笔记本电脑)