1

I'm using startDeviceMotionUpdates for my apple watch app, and it is not working. Following is my code:

import WatchConnectivity
import CoreMotion

class ResultInterfaceController: WKInterfaceController, WCSessionDelegate {

    var deviceQueue = OperationQueue()
    var motionManager = CMMotionManager()

    override func awake(withContext context: Any?) {
    super.awake(withContext: context)

        self.motionManager.deviceMotionUpdateInterval = 0.5

        motionManager.startDeviceMotionUpdates(to: deviceQueue) { deviceManager, error in
            print("Success")
        }
        print(motionManager.isDeviceMotionActive)   // returns false
   }
}

Output is: false

I am unable to identify the issue. Please help

Aawara
  • 301
  • 3
  • 18
  • Did you check the value of `isDeviceMotionAvailable`? – Dave Weston Feb 09 '17 at 02:33
  • @DaveWeston I checked it now, and returning 'false'. I'm checking it in 'simulator'. So is that because of that? – Aawara Feb 09 '17 at 05:45
  • 1
    I tested it on real device too. Even it's not working – Aawara Feb 09 '17 at 07:38
  • From this question and answer: http://stackoverflow.com/questions/32466314/apple-watch-cmdevicemotion-is-not-giving-me-good-readings, it seems that only the accelerometer is available on the Apple Watch. – Dave Weston Feb 09 '17 at 08:11
  • it Was. I am using watch with os 2. In this, accelerometer and all other things are also present. The problem is that, I am unable to trace it – Aawara Feb 09 '17 at 09:01
  • https://developer.apple.com/reference/coremotion/cmmotionmanager#overview – Aawara Feb 09 '17 at 10:11
  • Yes, the API is available on watchOS 2, but the device itself only provides accelerometer data. The answer I linked to stated that the watch pulls data from the watch for the other core motion sources. I assume if the watch isn't currently linked or the phone is out of range, it won't even be able to do that. – Dave Weston Feb 12 '17 at 03:36
  • I thought I had the same but found out that it was not the same prob you had. https://stackoverflow.com/questions/24114164/motion-manager-is-not-working-in-swift this answer works for me. Hope this comment can help someone else. – AiShiguang Nov 16 '22 at 09:42

0 Answers0