问题描述
有没有办法识别设备类型(智能手机、平板电脑、笔记本电脑)?我需要将设备类型标识为:智能手机、平板电脑、笔记本电脑……我尝试使用 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) .
那么如果它的手机"=>我怎么能做一些会给我的代码呢?智能手机,如果它的未知"=>笔记本电脑/计算机,它也会保存在我的异步存储中.
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:
有很多 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.
这篇关于REACT NATIVE:有没有办法识别设备类型(智能手机、平板电脑、笔记本电脑)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!