作者:手机用户2502862793 | 来源:互联网 | 2023-02-01 19:12
我刚用iOS 11 SDK重建了我的应用程序,试图删除blue banner
现在总是出现的应用程序.我想 - "太棒了,有用",却发现定位服务现在根本不起作用.
用于iOS 10的应用程序 - 有没有人听到过什么?
1> William Geor..:
苹果似乎又添加了另一项隐私功能.用户现在能够覆盖我们requestAlwaysAuthorization
并将其降级为requestWhenInUseAuthorization
- 这意味着作为开发人员,我们现在必须提供两个描述Info.plist
我发现他们已经添加了一个新密钥 NSLocationAlwaysAndWhenInUseUsageDescription
/*
* Either the NSLocationAlwaysAndWhenInUseUsageDescription key or both the
* NSLocationAlwaysUsageDescription and NSLocationWhenInUseUsageDescription
* keys must be specified in your Info.plist; otherwise, this method will do
* nothing, as your app will be assumed not to support Always authorization.
*/
然而,在使用这个新密钥时 - 位置服务仍然无法工作,在进一步搜索时,我发现这个宝石混入了所有额外的调试信息:
此应用尝试访问隐私敏感数据,但没有使用说明.应用程序的Info.plist必须包含NSLocationAlwaysAndWhenInUseUsageDescription和NSLocationWhenInUseUsageDescription键,并带有字符串值,向用户解释应用程序如何使用此数据
这与我在更新CLLocationManager.h
文件中找到的注释直接相矛盾.所以我创造了一个雷达.
好消息,如果你按照调试控制台的建议,IE.添加新密钥NSLocationAlwaysAndWhenInUseUsageDescription
和旧密钥之一NSLocationWhenInUseUsageDescription
,位置服务将重新开始工作.
不幸的是,用户现在得到了三个答案的对话,其中由于用户不耐烦而最有可能被击中的是最佳选择:"仅在使用应用程序时".这将导致需要始终使用的应用程序无用,除非用户经历了之后再次更改设置的所有麻烦.当应用程序要求时,至少"始终允许"应该是最佳选择!
我面临着非常相似的情况.只有我在iOS 10.2中测试,并且我在我的Info.plist中添加了"NSLocationAlwaysUsageDescription",这是我需要的权限.但我在控制台中收到上述消息,说我还需要添加`NSLocationWhenInUseUsageDescription`.
2> Heider Sati..:
只是添加修复此步骤的步骤:
2种方法:
A)简单的方法:选择你的Info.plist文件,添加属性,注意它们以PRIVCY而不是LOCATION开头...因此,这些变量的确切名称以"Privacy - Location ..."等开头,添加每个都在这里,并描述用户将如何在警告上看到这一点.
B)硬/有趣/程序化的方式(我更喜欢这种方式):
右键单击您的应用程序的Info.plist,然后选择"查看源代码",您应该在XML中看到它,
遵循其他......格式,并添加以下属性:
NSLocationAlwaysUsageDescription
Program requires GPS to track cars and job orders
NSLocationAlwaysAndWhenInUseUsageDescription
Program requires GPS to track cars and job orders
NSLocationWhenInUseUsageDescription
Program requires GPS to track cars and job orders
NSMicrophoneUsageDescription
This app uses your Microphone to allow Voice over IP communication with the Program Admin system
单击保存,然后右键单击info.plist文件,然后选择属性列表,这应该将文件返回到默认视图.
编辑:
另一位成员要求代码,这里是:
1)在.H文件中,添加:
@property (strong, nonatomic) CLLocationManager *LocationManager;
2)在.M文件上添加ViewDidAppear()函数:
_LocatiOnManager= [[CLLocationManager alloc] init];
[_LocationManager setDelegate:self];
_LocationManager.desiredAccuracy = kCLLocationAccuracyBestForNavigation;
_LocationManager.pausesLocatiOnUpdatesAutomatically= NO;
[_LocationManager requestAlwaysAuthorization];
_LocationManager.headingFilter = 5;
_LocationManager.distanceFilter = 0;
[_LocationManager startUpdatingLocation];
[_LocationManager startUpdatingHeading];
这对我来说很好,希望代码也适合你.
问候
海德
3> iDoc..:
在iOS11下我发现,Info.plist在Info.plist中至少需要NSLocationAlwaysAndWhenInUseUsageDescription:
当您的应用程序是多语言时,奇怪的是,您的字符串的本地化版本需要此帖子中提到的所有三个键,requestAlwaysAuthorization()
并且locationManager(_ manager: CLLocationManager, didChangeAuthorization status: CLAuthorizationStatus)
将无声地失败.
拍摄显示德语翻译为例:
希望这可以节省你绊倒的时间.
4> Keshav Gera..:
在Swift 4.0.3中工作
NSLocationAlwaysAndWhenInUseUsageDescription
Description
NSLocationAlwaysUsageDescription
Will you allow this app to always know your location?
NSLocationWhenInUseUsageDescription
Do you allow this app to know your current location?
5> mhit0..:
跟着这些步骤:
我遇到了一个需要"始终授权"的应用程序遇到了同样的问题,并通过以下步骤解决了这个问题:
1. 添加 NSLocationWhenInUseUsageDescription
密钥Info.plist
2. 添加 NSLocationAlwaysAndWhenInUseUsageDescription
到Info.plist
3. 添加 NSLocationAlwaysUsageDescription
到Info.plist
(支持
4. 之前致电 )requestWhenInUseAuthorization()
requestAlwaysAuthorization(
您无法在requestWhenInUseAuthorization()之前执行requestAlwaysAuthorization().您必须升级到该权限级别.完成这些更改后,位置更新再次开始正常工作.
更多详情可在这找到:
https://developer.apple.com/documentation/corelocation/choosing_the_authorization_level_for_location_services/requesting_always_authorization
6> Abhishek Bed..:
比抱歉更安全..
在iOS 11中:添加以下内容,你很好.
NSLocationWhenInUseUsageDescription
Description
NSLocationAlwaysAndWhenInUseUsageDescription
Description
NSLocationAlwaysUsageDescription
Description