I'm making an app that will record user acceleration for a duration on the Apple Watch and send that data to the paired iPhone. I'm using the CoreMotion framework to achieve this.
My issue: I've been using a CMSensorRecorder object to record the data. This worked for a while, but CMSensorRecorder.authorizationStatus() is now "not authorised".
I've had a NSMotionUsageDescription in the info.plist files of both the watch and phone apps since the beginning. I've removed and re-added these, with no luck.
I recall the app displaying a prompt to allow motion tracking, but can't recreate the ability to display the prompt. Would greatly appreciate any advice on how to enable CMSensorRecorder again. Cheers.
My code initialising CMSensorRecorder:
if CMSensorRecorder.isAccelerometerRecordingAvailable(){
if CMSensorRecorder.authorizationStatus() == .authorized {
print("\(Date()): recorder started")
DispatchQueue.global(qos: .background).async {
DispatchQueue.global(qos: .background).sync{
self.dateStart = Date()
self.recorder.recordAccelerometer(forDuration: self.duration)
}
}
}
else {
print("\(CMSensorRecorder.authorizationStatus())")
self.xAccLabel.setText("not authorised")
}
}
else {
print ("Recording not available")
self.xAccLabel.setText("Not available")
}
Found THIS thread for that and there is one answer for that which says:
So for
authorizationI triedstartActivityUpdateslike shown belowand you need to declare
let activityManager = CMMotionActivityManager()And once user allow it
if CMSensorRecorder.authorizationStatus() == .authorized {will betrue.