iOS Developer Library

Developer

CoreMotion Framework Reference CMMagnetometerData Class Reference

Options
Deployment Target:

On This Page
Language:

CMMagnetometerData

Instances of the CMMagnetometerData class encapsulated measurements of the magnetic field made by the device’s magnetometer.

Your application can obtain samples of magnetometer measurements, as represented by instances of this class, from the block handler of the startMagnetometerUpdatesToQueue:withHandler: method or from the magnetometerData property of the CMMotionManager class.

Inheritance


Import Statement


Swift

import CoreMotion

Objective-C

@import CoreMotion;

Availability


Available in iOS 5.0 and later.
  • Returns the magnetic field measured by the magnetometer. (read-only)

    Declaration

    Swift

    var magneticField: CMMagneticField { get }

    Objective-C

    @property(readonly, nonatomic) CMMagneticField magneticField

    Discussion

    The value of this property is the total magnetic field observed by the device which is equal to the Earth’s geomagnetic field plus bias introduced from the device itself and its surroundings.

    This is the “raw” magnetic-field value, unlike the calibrated value of the magneticField property of CMDeviceMotion which filters out the bias introduced by the device and, in some cases, its surrounding fields.

    Import Statement

    Objective-C

    @import CoreMotion;

    Swift

    import CoreMotion

    Availability

    Available in iOS 5.0 and later.