Testing for Sensors

As you read earlier in this chapter, you can use the application’s Info.plist file to require or exclude onboard sensors. You can also test in-app for each kind of sensor support by querying a Core Motion CMMotionManager object:

if (motionManager.gyroAvailable)     [motionManager startGyroUpdates]; if (motionManager.magnetometerAvailable)     [motionManager startMagnetometerUpdates]; if (motionManager.accelerometerAvailable)     [motionManager startAccelerometerUpdates]; if (motionManager.deviceMotionAvailable)     [motionManager startDeviceMotionUpdates];

Get The Core iOS Developer’s Cookbook, Fifth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.