首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >iOS 8 requestWhenInUseAuthorization无弹出窗口

iOS 8 requestWhenInUseAuthorization无弹出窗口
EN

Stack Overflow用户
提问于 2014-07-20 19:40:43
回答 5查看 39.2K关注 0票数 49

我试着让我的AppProject iOS 8准备就绪。我读了很多关于

代码语言:javascript
复制
[_locationManager requestWhenInUseAuthorization];

和plist中的条目

代码语言:javascript
复制
NSLocationWhenInUseUsageDescription

所以我更改了所有必要的代码行。

它工作得很好,但现在我已经从我的iOS 7基础上复制了我的项目,以包含新功能。但是,当我对iOS8位置隐私进行更改时,弹出窗口不再出现。

我的代码一直在工作,直到我复制它。

代码语言:javascript
复制
<?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>

这是我的电话

代码语言:javascript
复制
- (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;
}

我该如何解决这个问题呢?

EN

回答 5

Stack Overflow用户

发布于 2014-08-27 15:38:16

尝试用Info.plist编写NSLocationWhenInUseUsageDescription

票数 19
EN

Stack Overflow用户

发布于 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文件:

代码语言:javascript
复制
@interface SomeController : UIViewController <CLLocationManagerDelegate>

@property (strong, nonatomic) CLLocationManager *locationManager;

*.m文件:

代码语言:javascript
复制
- (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];
}

希望这能节省一些人的时间!谢谢。

票数 10
EN

Stack Overflow用户

发布于 2016-02-16 04:35:38

这里有个小问题。确保将NSLocationAlwaysUsageDescription或NSLocationWhenInUseUsageDescription键添加到主包plist中,而不是测试目标plist中!

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24850128

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档