panthor314
panthor314

Reputation: 318

iOS Application crashing on use of CMPedometer functions

I have a Xamarin.iOS application where I am using this guide to make use of the CMPedometer floors ascended property. Here is some relevant code on my single view app:

CMPedometer pedometer;
...
public override async void ViewDidLoad(){
    base.ViewDidLoad();
    if (CMPedometer.IsFloorCountingAvailable)
        {
            pedometer = new CMPedometer();
            //app crashes here:
            pedometer.StartPedometerUpdates(new NSDate(), UpdatePedometerData);

            var data = await pedometer.QueryPedometerDataAsync((NSDate)DateTime.SpecifyKind(DateTime.Now.AddHours(-24), DateTimeKind.Utc), (NSDate)DateTime.Now);
            UpdatePedometerData(data, null);

        }

}

My very basic app crashes when I try to get updates from my CMPedometer with little error output. This is what I get:

=================================================================
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.
=================================================================

which may be an issue with my app permissions? If that's the case I am not sure how to grant/ask permissions on using the CDPedometer. Thanks for any help

Upvotes: 2

Views: 400

Answers (2)

Victor Chelaru
Victor Chelaru

Reputation: 4817

Thanks to @panthor314 for getting me pointed in the right direction. Unfortunately the blog link above is dead, but this seems to be the new location for this information:

https://learn.microsoft.com/en-us/xamarin/ios/app-fundamentals/security-privacy?tabs=windows

This link explains:

Apps that fail to provide the required keys will be silently terminated by the system when they attempt to access one of the restricted features or user information, without error! If an app starts unexpectedly failing on iOS 10, ensure that all of the required Info.plist have been specified.

The relevant privacy key is NSMotionUsageDescription:

Motion Usage Description (NSMotionUsageDescription) - Allows the developer to describe why the app wants to access the device's accelerometer.

To add the property:

  1. Right-click on Info.plist in your Solution Explorer (double click seems to open a different window)
  2. Select Open With...
  3. Select Generic PList Editor and click OK
  4. At the end of the plist, click the + icon to add a new entry
  5. Change Custom Property to Privacy - Motion Usage Description enter image description here
  6. Enter text to display to the user about accessing steps such as "This application would like to access your steps data"
  7. Save the file and run the application again

Upvotes: 0

panthor314
panthor314

Reputation: 318

Got this link. You have to add privacy setting for motion in your plist

https://blog.xamarin.com/new-ios-10-privacy-permission-settings/

Upvotes: 2

Related Questions