有什么方法可以识别设备类型(智能手机,平板电脑,笔记本电脑)? 我需要将设备类型标识为:智能手机,平板电脑,笔记本电脑.. 我尝试使用“ 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');
}
};
答案 0 :(得分:4)
在提到的react-native-device-info
中,有一种方法getDeviceType()
返回
Handset
(用于智能手机)Tablet
(平板电脑)Tv
用于电视和unknown
用于其他所有内容(很可能是笔记本电脑)答案 1 :(得分:2)
根据API DOC,您可以使用以下API来检测设备类型:
要获取设备名称或任何其他用例的API太多了。阅读API文档:)据我所知,您也无法检测到laptop
,React Native在PC上不可用。