简体   繁体   中英

The app's Info.plist must contain an NSMotionUsageDescription key

I am getting the following error during the runtime:

This app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSMotionUsageDescription key with a string value explaining to the user how the app uses this data.

I have added the key to the plist file:

<!-- 🏊 Motion -->
<key>NSMotionUsageDescription</key>
<string>This app needs to be able to access your motion use</string>

and this the code in AppDelegate:

if ([CMMotionActivityManager isActivityAvailable])
{
    CMMotionActivityManager *motionManager = [[CMMotionActivityManager alloc] init];
    NSOperationQueue *motionActivityQueue = [[NSOperationQueue alloc] init];

    [motionManager queryActivityStartingFromDate:[NSDate distantPast] toDate:[NSDate date] toQueue:motionActivityQueue withHandler:^(NSArray *activities, NSError *error) {
        if (error && (error.domain == CMErrorDomain) && (error.code == CMErrorMotionActivityNotAuthorized)) {

        } else if (activities || !error) {

        }

        dispatch_async(dispatch_get_main_queue(), ^{

        });
    }];        
}

Why am I keep getting this crash? I deleted all the derived folder, cleaned the project. But still asking me the key? Is it an Apple bug?

I found the problem. I hope one day it will help someone. Go to Project Settings -> Info -> Under the Custom iOS Target Properties section find the Required background modes and add your key here as well. I don't know why not all my plist file keys are here.

Go to Targets -> your project target -> build settings -> search for NSMotionUsageDescription

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM