Mar*_*cus 49 privacy objective-c geolocation ios8
我试着让我的AppProject iOS 8准备就绪.我读过很多关于
[_locationManager requestWhenInUseAuthorization];
Run Code Online (Sandbox Code Playgroud)
和plist中的条目
NSLocationWhenInUseUsageDescription
Run Code Online (Sandbox Code Playgroud)
所以我改变了所有必要的代码行.
它工作正常,但现在我再次从我的iOS 7基础复制我的项目以包含新功能.但是当我对iOS8位置隐私进行更改时,弹出窗口不再出现了.
我的代码一直有效,直到我复制
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>NSLocationWhenInUseUsageDescription</key>
<string>tolle sache </string>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>fapporite.${PRODUCT_NAME:rfc1034identifier}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundlePackageType</key>
<string>BNDL</string>
<key>CFBundleShortVersionString</key>
<string>1.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>1</string>
</dict>
</plist>
Run Code Online (Sandbox Code Playgroud)
这是我的电话
- (instancetype)initWithCoder:(NSCoder *)coder
{
self = [super initWithCoder:coder];
if (self) {
_UserLocation = [[CLLocation alloc]init];
_locationManager = [[CLLocationManager alloc]init]; // initializing locationManager
_locationManager.delegate = self;
_locationManager.desiredAccuracy = kCLLocationAccuracyBest; // setting the accuracy
[_locationManager requestWhenInUseAuthorization]; // iOS 8 MUST
[_locationManager startUpdatingLocation]; //requesting location updates
NSLog(@"passed initwithcode");
}
return self;
}
Run Code Online (Sandbox Code Playgroud)
我怎样才能解决这个问题?
Gro*_*oot 101
从文档中
NSLocationWhenInUseUsageDescription(String-iOS)描述了应用程序在前台运行时正常访问用户位置的原因.当您的应用使用位置服务直接跟踪用户的当前位置时,请包含此密钥.此密钥不支持使用位置服务来监控区域或使用重要位置更改服务监控用户的位置.系统在请求使用位置服务的权限时,在向用户显示的警报面板中包含此密钥的值.
当您使用CLLocationManager类的requestWhenInUseAuthorization方法请求位置服务的授权时,此密钥是必需的.如果在不包含此密钥的情况下调用requestWhenInUseAuthorization方法时密钥不存在,系统将忽略您的请求.
iOS 8.0及更高版本支持此密钥.如果Info.plist文件包含此密钥和NSLocationUsageDescription密钥,则系统将使用此密钥并忽略NSLocationUsageDescription密钥.
在这里阅读它.
我发现将此密钥添加到info.plist的最简单方法是右键单击info.plist并选择
打开As->源代码
然后添加下面到底前 </dict></plist>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
Run Code Online (Sandbox Code Playgroud)
如果您愿意,可以在其间添加一个文本,<string></string>向用户描述您为什么要使用他/她的位置.此文本将显示在警报中的默认文本下.
小智 19
尝试在Info.plist中编写NSLocationWhenInUseUsageDescription
ser*_*e-k 10
iOS 8.3,Xcode 6.3.1,ARC启用
这个问题已经解决,但我有(2)从我最近参与CLLocationManager中添加的注意事项.
1)您必须在*.plist文件中输入以下密钥:

最常用的密钥具有通用的更具描述性的名称,例如"隐私 - 位置使用描述",它实际上是"NSLocationUsageDescription"密钥.
要查看"原始"键名称,请转到"*-Info.plist"并右键单击列出键的导航器区域,如下所示:

并且您得到以下结果:

与本文相关的三个键是:

2)在尝试请求授权或更新位置之前,请确保分配并初始化CLLocationManager的实现.
*.h文件:
@interface SomeController : UIViewController <CLLocationManagerDelegate>
@property (strong, nonatomic) CLLocationManager *locationManager;
Run Code Online (Sandbox Code Playgroud)
*.m文件:
- (IBAction)locationButton:(UIButton *)sender
{
if (self.locationManager == nil)
{
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
}
else
{
nil;
}
if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)])
{
[self.locationManager requestWhenInUseAuthorization];
}
else
{
nil;
}
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
[self.locationManager startUpdatingLocation];
}
Run Code Online (Sandbox Code Playgroud)
希望这能节省一些时间!谢谢.
| 归档时间: |
|
| 查看次数: |
38255 次 |
| 最近记录: |