Gyroscope and Magnometer Data on Apple Watch

Hi

I am having an issue accessing gyroscope and magnometer data through CoreMotion. I have an apple watch 6 (os 7.6), iPhone XS max (ios 14.7) and XCode 12.5.1. I did write a simple application to print the accel, gyro and magno data. It works on the phone but not on the watch. On the watch, it only gives me accel data and when I do isGyroAvailable or isMagnoAvailable I get False, while isAccelAvailable gives me True. Should I turn on something? Maybe an authentication flag? Any help will be greatly appreciated.

Answered by Sorush in 684014022

Actually, I fixed it!

   let motionManagerDelegate = CMMotionManager()
  var sensorDataDelegate=[Double]()
     print("sensor function starts==============================",currentTime)
     
    if self.motionManagerDelegate.isDeviceMotionAvailable {
      if !self.motionManagerDelegate.isDeviceMotionActive{
        self.motionManagerDelegate.deviceMotionUpdateInterval = 30 / 60.0
        self.motionManagerDelegate.showsDeviceMovementDisplay = true
      }
        self.motionManagerDelegate.startDeviceMotionUpdates(using: .xMagneticNorthZVertical, to: OperationQueue.current!, withHandler: { (data, error) in
          if let validData = data {
            let rX = validData.rotationRate.x
            let rY = validData.rotationRate.y
            let rZ = validData.rotationRate.z
            let timeStamp=validData.timestamp
            if self.offsetTimeFlag{
//              let currentTime=Date().timeIntervalSince1970
//              self.offsetTime=currentTime-timeStamp
              self.offsetTime = 0.0-timeStamp
              self.offsetTimeFlag=false
            }
            self.sensorDataDelegate.append(contentsOf: [timeStamp+self.offsetTime])
          }
        })
    }
    else {
      fatalError("The motion data is not avaialable")
    }
Accepted Answer

Actually, I fixed it!

   let motionManagerDelegate = CMMotionManager()
  var sensorDataDelegate=[Double]()
     print("sensor function starts==============================",currentTime)
     
    if self.motionManagerDelegate.isDeviceMotionAvailable {
      if !self.motionManagerDelegate.isDeviceMotionActive{
        self.motionManagerDelegate.deviceMotionUpdateInterval = 30 / 60.0
        self.motionManagerDelegate.showsDeviceMovementDisplay = true
      }
        self.motionManagerDelegate.startDeviceMotionUpdates(using: .xMagneticNorthZVertical, to: OperationQueue.current!, withHandler: { (data, error) in
          if let validData = data {
            let rX = validData.rotationRate.x
            let rY = validData.rotationRate.y
            let rZ = validData.rotationRate.z
            let timeStamp=validData.timestamp
            if self.offsetTimeFlag{
//              let currentTime=Date().timeIntervalSince1970
//              self.offsetTime=currentTime-timeStamp
              self.offsetTime = 0.0-timeStamp
              self.offsetTimeFlag=false
            }
            self.sensorDataDelegate.append(contentsOf: [timeStamp+self.offsetTime])
          }
        })
    }
    else {
      fatalError("The motion data is not avaialable")
    }
Gyroscope and Magnometer Data on Apple Watch
 
 
Q