React Native: How to Determine if Device is iPhone or iPad

后端 未结 10 1031
花落未央
花落未央 2021-02-01 16:32

I know with React Native that we have the ability to determine whether iOS or Android is being run using the Platform module, but how can we determine what device i

10条回答
  •  名媛妹妹
    2021-02-01 17:10

    If you're looking for a way to do that without including 3rd party libraries (like react-native-device-info) you can also do:

    import { NativeModules } from 'react-native';
    const { PlatformConstants } = NativeModules;
    const deviceType = PlatformConstants.interfaceIdiom;
    

    deviceType can take the values: phone, pad, tv, carplay and unknown.

提交回复
热议问题