我试着让我的AppProject iOS 8准备就绪。我读了很多关于
[_locationManager requestWhenInUseAuthorization];
和plist中的条目
NSLocationWhenInUseUsageDescription
所以我更改了所有必要的代码行。
它工作得很好,但现在我已经从我的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>
这是我的电话
- (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;
}
我该如何解决这个问题呢?
发布于 2014-08-27 15:38:16
尝试用Info.plist编写NSLocationWhenInUseUsageDescription
发布于 2015-05-15 06:49:44
iOS 8.3、Xcode 6.3.1、启用ARC
这个问题已经解决了,但我最近参与了CLLocationManager的工作,有(2)个注释要补充。
1)您必须在*.plist文件中输入以下密钥:
最常用的键具有更具描述性的通用名称,例如"Privacy - Location Usage Description",它实际上是"NSLocationUsageDescription“键。
要查看“原始”键名称,请转到"*-Info.plist“,然后在列出键的导航区中单击鼠标右键,如下所示:
您会得到以下结果:
与本文相关的三个关键字是:
2)在尝试请求授权或更新位置之前,请确保您已分配并初始化了CLLocationManager的实现。
*.h文件:
@interface SomeController : UIViewController <CLLocationManagerDelegate>
@property (strong, nonatomic) CLLocationManager *locationManager;
*.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];
}
希望这能节省一些人的时间!谢谢。
发布于 2016-02-16 04:35:38
这里有个小问题。确保将NSLocationAlwaysUsageDescription或NSLocationWhenInUseUsageDescription键添加到主包plist中,而不是测试目标plist中!
https://stackoverflow.com/questions/24850128
复制相似问题