gpt4 book ai didi

objective-c - iOS 8 requestWhenInUseAuthorization 没有弹出

转载 作者:IT老高 更新时间:2023-10-28 11:35:19 28 4
gpt4 key购买 nike

我试图让我的 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;
}

我该如何解决这个问题?

最佳答案

来自文档

NSLocationWhenInUseUsageDescription (String - iOS) describes the reason why the app accesses the user’s location normally while running in the foreground. Include this key when your app uses location services to track the user’s current location directly. This key does not support using location services to monitor regions or monitor the user’s location using the significant location change service. The system includes the value of this key in the alert panel displayed to the user when requesting permission to use location services.

This key is required when you use the requestWhenInUseAuthorization method of the CLLocationManager class to request authorization for location services. If the key is not present when you call the requestWhenInUseAuthorization method without including this key, the system ignores your request.

This key is supported in iOS 8.0 and later. If your Info.plist file includes both this key and the NSLocationUsageDescription key, the system uses this key and ignores the NSLocationUsageDescription key.

阅读 here .

我发现将此键添加到 info.plist 的最简单方法是右键单击 info.plist 并选择

打开为->源代码

然后在最后before </dict></plist>

<key>NSLocationWhenInUseUsageDescription</key>
<string></string>

如果您愿意,可以在 <string></string> 之间添加文本向用户描述您为什么要使用他/她的位置。此文本将显示在警报的默认文本下。

关于objective-c - iOS 8 requestWhenInUseAuthorization 没有弹出,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24850128/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com