问题描述
有什么方法可以识别设备类型(智能手机,平板电脑,笔记本电脑)?我需要将设备类型标识为:智能手机,平板电脑,笔记本电脑..我尝试使用"react-native-device-info" API库,但不了解如何识别3种特定设备类型(智能手机,平板电脑,笔记本电脑).
There is way to identify a device type (smartphone, tablet, laptop) ?I need to identify a device type as: smartphone, tablet, laptop ..i try to use the "react-native-device-info" api library but dont understand how to identify the 3 specific devices type (smartphone, tablet, laptop) .
那么如果它的"Handset" =>我该怎么做才能给我一些代码呢?智能手机(如果其未知" ==)笔记本电脑/计算机,它也将保存在我的异步存储中.
So 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.
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');
}
};
推荐答案
根据 API DOC ,您可以使用以下API来检测设备类型:
According to API DOC you can use these APIs to detect the device types:
- getDeviceType
- isTablet
- isEmulator
- getModel
有太多的API可以获取设备名称或任何其他用例.阅读API文档:)据我所知,您也无法检测到laptop
,React Native在PC上不起作用.
There are so many APIs to get the device name or any other use-cases. Read the API doc :) Also you cannot detect the laptop
as far as I know, React Native does not for on PC.
这篇关于反应本机:有什么方法可以识别设备类型(智能手机,平板电脑,笔记本电脑)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!