[英]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.应用程序的 Info.plist 必须包含一个 NSMotionUsageDescription 键和一个字符串值,向用户解释应用程序如何使用此数据。
I have added the key to the plist file:我已将密钥添加到 plist 文件中:
<!-- 🏊 Motion -->
<key>NSMotionUsageDescription</key>
<string>This app needs to be able to access your motion use</string>
and this the code in AppDelegate:这是 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. 转到项目设置 - >信息 - >在自定义iOS目标属性部分下,找到所需的背景模式,并在此处添加您的密钥。 I don't know why not all my plist file keys are here. 我不知道为什么我的所有plist文件键都不在这里。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.