See Also: CMMotionManager Members
Core Motion was introduced in iOS 7 and is not available on all devices (the iPhone 5S was the first phone to have the necessary coprocessor and the iPad Air 2 was the first tablet). Developers can check if Core Motion is available with CMMotionManager.DeviceMotionAvailable.
Applications that wish to access Core Motion must have an entitlements.plist file.
Users must explicitly grant access to Core Motion via a standard privacy dialog. Unlike most functions that require user permissions, there is not a corresponding API to check status. However, applications can perform a query and, if authorization is not available, will receive an error of type CMError.MotionActivityNotAuthorized. This technique is shown in the following example:
C# Example
var stepCounter = new CMStepCounter (); stepCounter.QueryStepCount( NSDate.FromTimeIntervalSinceNow(-60 * 60 * 24), NSDate.Now, NSOperationQueue.MainQueue, ((steps, error) => { if(error != null && error.Code == (int) CMError.MotionActivityNotAuthorized) { motionStatus = "Not Authorized"; UpdateStatus(); } else { motionStatus = "Available"; var stepMsg = String.Format("You have taken {0} steps in the past 24 hours", steps); InvokeOnMainThread(() => { stepsMessage.Text = stepMsg; UpdateStatus(); }); } }));