This is Xamarin's bug tracking system. For product support, please use the support links listed in your Xamarin Account.
Bug 44709 - [watchOS] CMDeviceMotion properties aren't all populated with data/cause crash
Summary: [watchOS] CMDeviceMotion properties aren't all populated with data/cause crash
Status: VERIFIED FIXED
Alias: None
Product: iOS
Classification: Xamarin
Component: Xamarin.WatchOS.dll (show other bugs)
Version: XI 10.0 (iOS10)
Hardware: PC Mac OS
: --- normal
Target Milestone: (C9)
Assignee: Ivan Herrera
URL:
Depends on:
Blocks:
 
Reported: 2016-09-24 04:12 UTC by CraigD
Modified: 2017-01-11 11:14 UTC (History)
5 users (show)

See Also:
Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
sample Xamarin watchOS project demonstrating issue (130.38 KB, application/zip)
2016-09-24 04:12 UTC, CraigD
Details

Description CraigD 2016-09-24 04:12:03 UTC
Created attachment 17725 [details]
sample Xamarin watchOS project demonstrating issue

TL;DR not sure if there is a binding problem with three properties on CMDeviceMotion:Gravity, UserAcceleration, MagneticField. Testing on iPhone 7Plus, Watch Series 1, watchOS 3, Xamarin stable, Xcode 8

---

The attached Xamarin watchOS project is an attempted port of:
https://developer.apple.com/library/prerelease/content/samplecode/SwingWatch/Introduction/Intro.html

Summary of code:

```
CMMotionManager motionManager = new CMMotionManager();
motionManager.DeviceMotionUpdateInterval = sampleInterval;
motionManager.StartDeviceMotionUpdates(queue, (deviceMotion, error) =>
{
   Console.WriteLine(deviceMotion);
   Console.WriteLine(deviceMotion.Attitude);
   Console.WriteLine(deviceMotion.MagneticField);
//   Console.WriteLine(deviceMotion.Gravity);            // CRASHES
//   Console.WriteLine(deviceMotion.UserAcceleration);   // CRASHES
//   Console.WriteLine(deviceMotion.MagneticField);      // CRASHES
}
```

The `deviceMotion`, `Attitude` and `MagneticField` are all valid objects that work as expected (output example shown below).

BUT the other properties (Gravity, UserAcceleration, MagneticField) cause the app to crash immediately if any of them are referenced (they're structs, so I can't do a null check), and the crash occurs even if wrapped in try{}catch{} block.

Example output of the working properties (streams as device is moved):

deviceMotion>QuaternionX 0.069977 QuaternionY - 0.273441 QuaternionZ 0.580755 QuaternionW - 0.763582 UserAccelX - 0.343605 UserAccelY - 0.612576 UserAccelZ - 0.128299 RotationRateX 0.010139 RotationRateY - 0.001787 RotationRateZ - 0.010357 MagneticFieldX 0.000000 MagneticFieldY 0.000000 MagneticFieldZ 0.000000 MagneticFieldAccuracy - 1 @ 79268.313185
deviceMotion.Attitude>Pitch: -25.117162, Roll: 21.804014, Yaw: -69.597130
deviceMotion.MagneticField>((0,0,0),Uncalibrated)



NOTE: to use the sample app attached, once it starts Force Touch to show the Start button.
NOTE2: the Swift example runs fine on my hardware.
Comment 1 Vincent Dondain 2016-09-29 18:39:25 UTC
@rolf could confirm this bug porfavor? I do not currently have a watchOS 3 device and the test case is full of watchOS 3 only APIs.

The bug report looks very complete though thanks Craig.
Comment 2 Rolf Bjarne Kvinge 2016-10-03 13:07:40 UTC
I can reproduce.

Note You need to log in before you can comment on or make changes to this bug.