问题描述
我正在尝试使用单元测试 (xctest) 测试 CoreLocation,但未能通过权限阶段.我特别收到一条假定的错误消息,见下文(*).
I am attempting to test CoreLocation with a unit test (xctest), this failing to get past the permissions stage. I specifically get an assumed error message,see below(*).
我正在使用 authorizationStatus 方法,但这对我不起作用.
I am swizzling the authorizationStatus method but this not working for me.
[MySwizzler swizzleClass:[CLLocationManager class]
method:@"authorizationStatus"
instanceMethod:NO];
+ (CLAuthorizationStatus)override_authorizationStatus {
return myAuthorizationStatus;
}
一旦我请求授权:
[[self locationManager] requestWhenInUseAuthorization];
我收到回电:
-(void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
状态为:
kCLAuthorizationStatusRestricted
我的 swizzled 方法从未被调用,我在日志中收到此消息:
My swizzled method never gets called and I get this message in my log:
(*)此应用试图访问隐私敏感数据而没有使用说明.应用的 Info.plist 必须包含一个 NSLocationWhenInUseUsageDescription 键,其中包含一个字符串值,向用户解释应用如何使用这些数据".
(*)"This app has attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSLocationWhenInUseUsageDescription key with a string value explaining to the user how the app uses this data".
我的 Plist 确实包含这个:
my Plist does contain this:
<plist version="1.0">
<dict>
<key>NSLocationUsageDescription</key>
<string>Required</string>
<key>NSLocationWhenInUseUsageDescription</key>
<string>Required</string>
</dict>
</plist>
- 并且我的 TestTarget Info.plist 属性设置为 Plist 的路径文件.
- 方案运行配置设置为允许位置模拟"
我假设我在这里使用了错误的方法,也许还有其他一些方法问题.
I am assuming I am swizzling the wrong method here and maybe some otherproblems.
请帮忙.
推荐答案
也许您将密钥添加到测试目标的 Info.plist 中?
Perhaps you added the keys to the Test target's Info.plist instead?
这篇关于xctest 此应用程序试图在没有使用说明的情况下访问隐私敏感数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!