This documentation is available as Markdown for AI agents and LLMs. See the full Markdown index or append .md to any documentation URL.
This is documentation for the next SDK version. For up-to-date documentation, see the latest version (SDK 57).
Expo 磁力计
一个提供访问设备磁力计传感器的库。
Magnetometer 来自 expo-sensors,提供对设备磁力计传感器的访问,以响应和测量以微特斯拉(μT)为单位的磁场变化。
你可以使用 Magnetometer 访问已校准的值,使用 MagnetometerUncalibrated 访问未校准的原始值。
安装
If you are installing this in an existing React Native app, make sure to install expo in your project.
用法
API
import { Magnetometer, MagnetometerUncalibrated } from 'expo-sensors';
Classes
Type: Class extends DeviceSensor<MagnetometerMeasurement>
Magnetometer Methods
Subscribe for updates to the magnetometer.
EventSubscriptionA subscription that you can call remove() on when you would like to unsubscribe the listener.
Checks user's permissions for accessing sensor.
Promise<PermissionResponse>Returns boolean which signifies if sensor has any listeners registered.
booleanYou should always check the sensor availability before attempting to use it.
Check the availability of the device magnetometer. Requires at least Android 2.3 (API Level 9) and iOS 8.
Promise<boolean>A promise that resolves to a boolean denoting the availability of the sensor.
Deprecated: use subscription.remove() instead.
voidAsks the user to grant permissions for accessing sensor.
Promise<PermissionResponse>Interfaces
A subscription object that allows to conveniently remove an event listener from the emitter.
Types
Each of these keys represents the strength of magnetic field along that particular axis measured in microteslas (μT).
Literal type: union
Permission expiration time. Currently, all permissions are granted permanently.
Acceptable values are: 'never' | number