Post

Replies

Boosts

Views

Activity

.isDeviceMotionAvailable returns true, but data from .deviceMotion is always nil
Hello everyone. I'm trying to work with Core Motion, getting readings from my Apple Watch (Series 4), but am getting inconsistent behaviour. If I run the code from Apple's Core Motion documentation - https://developer.apple.com/documentation/coremotion/getting_processed_device-motion_data (see Listing 1), I don't get any readings. The code I run, which works fine on iPhone, but not on Apple Watch, is: func startDeviceMotion() { if motion.isDeviceMotionAvailable { self.motion.deviceMotionUpdateInterval = 1.0 / 60.0 self.motion.showsDeviceMovementDisplay = true self.motion.startDeviceMotionUpdates(using: .xMagneticNorthZVertical) self.timer = Timer(fire: Date(), interval: (1.0 / 60.0), repeats: true, block: { (timer) in if let data = self.motion.deviceMotion { let x = data.attitude.pitch let y = data.attitude.roll let z = data.attitude.yaw } }) RunLoop.current.add(self.timer!, forMode: RunLoop.Mode.default) } } The problem is that although .isDeviceMotionAvailable returns true and runs the if statement correctly, the returned data from self.motion.deviceMotion only gives me nil's. I.e. DeviceMotion is available but still returns nil. What I have tried so far without luck, is: Adding various Accelerometer, Gyroscope, Location, and Privacy entries to my Info.plist Modifying the code: lowered the update interval checking for returned errors from the closure running it on a different thread Searched online for example projects, StackOverflow, etc., but without luck Run the code as an iPhone app. Here it works as expected without issues. I'm fairly new to this forum and Apple Development, so any help would be much appreciated!
3
0
1.7k
Apr ’21
Tracking "pointing direction" with Apple Watch
Hello everyone. Is it possible to track in which direction that a user is pointing while wearing an Apple Watch (in 3D space and in relation to true north)? And if so, which series of Apple Watches supports the hardware required to do this? I already did an iPhone prototype that can detect in which direction the phone is pointing (using quaternion readings from Core Motion), but am now looking to move this over to a watchOS app. I tried to find this information from Apple and online, but was not able to. Any help would be much appreciated!
0
0
781
Apr ’21