From the course: Advanced iOS App Development: Core Motion

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Detect devices

Detect devices - iOS Tutorial

From the course: Advanced iOS App Development: Core Motion

Start my 1-month free trial

Detect devices

- [Instructor] You saw with the pedometer that checking for sensors is important. Once again, you'll want to check for sensor availability in the user's device. This should always be the first step in launching your app: letting the user know they can't use this on their device. Go to ViewController.swift, close up the attributes inspector and the navigator. We won't be using either one of them. In ViewController go ahead and put in the import CoreMotion just under UIKit. There's a class CMMotionManager that manages device availability, pushing and pulling of sensor data. We'll use the Core Motion Manager for the gyro and accelerometer. Add the motion manager to the class. Let motionManager = CMMotionManager. Our first order of business is to check if the device has the sensors. We'll send an alert if any of the devices are unavailable. I'll also return that value so the rest of the app can decide to launch. So we're going to go ahead and add a function; isDevicesAvailable and it will…

Contents