Search code examples
c#xamarinxamarin.ioscore-motion

Starting CMMotionActivityManager gives SIGABRT


I am trying to detect motion activities in a native Xamarin.iOS app, running on an iPhone 6s. I am starting the manager like this:

var _manager = new CMMotionActivityManager();
_manager.StartActivityUpdates(new NSOperationQueue(), (activity) =>
{
    // do something with activity 
});

When I run the app, it is failing with this error:

2017-07-01 11:38:51.722 iosapp[1095:318780] critical: Native stacktrace:

2017-07-01 11:38:51.813 iosapp[1095:318780] critical: 0
libmonosgen-2.0.dylib 0x00000001007d5920 mono_handle_native_crash + 260 2017-07-01 11:38:51.813 iosapp[1095:318780] critical: 1 libsystem_platform.dylib
0x000000018ca1131c _sigtramp + 52 2017-07-01 11:38:51.813 iosapp[1095:318780] critical: 2 libsystem_kernel.dylib
0x000000018c9484d0 + 100 2017-07-01 11:38:51.813 iosapp[1095:318780] critical: 3 libsystem_kernel.dylib
0x000000018c9484fc system_set_sfi_window + 0 2017-07-01 11:38:51.813 iosapp[1095:318780] critical: 4 TCC
0x000000018fb64498 + 0 2017-07-01 11:38:51.813 iosapp[1095:318780] critical: 5 TCC
0x000000018fb643b8 + 0 2017-07-01 11:38:51.813 iosapp[1095:318780] critical: 6 TCC
0x000000018fb673d4 + 340 2017-07-01 11:38:51.813 iosapp[1095:318780] critical: 7 libxpc.dylib
0x000000018ca46f38 + 80 2017-07-01 11:38:51.814 iosapp[1095:318780] critical: 8 libxpc.dylib
0x000000018ca46ea8 + 40 2017-07-01 11:38:51.814 iosapp[1095:318780] critical: 9 libdispatch.dylib
0x000000018c80a9a0 + 16 2017-07-01 11:38:51.814 iosapp[1095:318780] critical: 10 libdispatch.dylib
0x000000018c8190d4 + 644 2017-07-01 11:38:51.814 iosapp[1095:318780] critical: 11 libdispatch.dylib
0x000000018c81aa50 + 540 2017-07-01 11:38:51.814 iosapp[1095:318780] critical: 12 libdispatch.dylib
0x000000018c81a7d0 + 124 2017-07-01 11:38:51.814 iosapp[1095:318780] critical: 13 libsystem_pthread.dylib
0x000000018ca13100 _pthread_wqthread + 1096 2017-07-01 11:38:51.814 iosapp[1095:318780] critical: 14 libsystem_pthread.dylib
0x000000018ca12cac start_wqthread + 4 2017-07-01 11:38:51.814 iosapp[1095:318780] critical: ================================================================= Got a SIGABRT while executing native code. This usually indicates a fatal error in the mono runtime or one of the native libraries used by your

application.

Is there something wrong with the way that I am instantiating the manager?


Solution

  • Solved. It was a permission issue with info.plist.

    From iOS Core Motion docs:

    Important An iOS app linked on or after iOS 10.0 must include usage description keys in its Info.plist file for the types of data it needs. Failure to include these keys will cause the app to crash. To access motion and fitness data specifically, it must include NSMotionUsageDescription.

    After I included this key in the info.plist:

    <key>NSMotionUsageDescription</key>
    <string>MotionActivity App needs Motion Access</string>
    

    it works like a charm.