iOS 8.1 CoreLocationManager requestWhenInUseAuthorization 没有提示 AlertView
<p><p>我正在尝试在我的 iOS 应用上使用用户位置。该应用适用于 iOS 7,但不适用于 iOS 8。</p>
<p>我都试过了。看了一堆教程,我知道在 iOS 8 中我们需要调用 requestWhenInUseAuthorization 方法并将 NSLocationWhenInUseUsageDescription 键添加到 Info.plist 中。</p>
<p>但它仍然无法正常工作,它没有征求用户的许可,我正在真实设备中进行测试(运行 iOS 8.1.x 的 iPhone 5c)。我多次尝试重新安装该应用程序。</p>
<p>这些是我为测试这个东西而创建的一个非常非常小的项目的代码。</p>
<p>我的 ViewController.m</p>
<pre><code>#import "ViewController.h"
#import <CoreLocation/CoreLocation.h>
@interface ViewController () <CLLocationManagerDelegate>
@property (strong, nonatomic) CLLocationManager *locationManager;
@end
@implementation ViewController
- (void)viewDidLoad {
;
self.locationManager = [ init];
self.locationManager.delegate = self;
self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.distanceFilter = kCLHeadingFilterNone;
if () {
NSLog(@"Pôde chamar o método"); // It could call the method
;
}
// ;
}
- (void)didReceiveMemoryWarning {
;
// Dispose of any resources that can be recreated.
}
#pragma mark - CLLocationManagerDelegate
- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
NSLog(@"Atualizou Localização para: %@", ); // Updated the location to
}
- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error {
NSLog(@"Location Manager falhou com erro: %@", error); // Location manager failed with error
}
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status {
if (status == kCLAuthorizationStatusAuthorized) {
;
}
}
@end
</code></pre>
<p>我的信息.plist</p>
<pre><code><?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>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleExecutable</key>
<string>$(EXECUTABLE_NAME)</string>
<key>CFBundleIdentifier</key>
<string>wallace.$(PRODUCT_NAME:rfc1034identifier)</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>CFBundleName</key>
<string>$(PRODUCT_NAME)</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>
<key>NSLocationWhenInUseUsageDescription</key>
<string></string>
</dict>
</plist>
</code></pre>
<p>有人知道如何解决这个问题吗?</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>将 <code>NSLocationAlwaysUsageDescription</code> 和 <code>NSLocationWhenInUseUsageDescription</code> 添加到您的 <code>Info.plist</code>。然后,您可以为每个值提供 AlertView 文本。</p>
<p>位置管理器将查看这些字段中的文本以在 AlertView 中进行提示。</p></p>
<p style="font-size: 20px;">关于iOS 8.1 CoreLocationManager requestWhenInUseAuthorization 没有提示 AlertView,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/28942516/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/28942516/
</a>
</p>
页:
[1]