gpt4 book ai didi

iOS 8.1 CoreLocationManager requestWhenInUseAuthorization 不提示 AlertView

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:17:08 25 4
gpt4 key购买 nike

我正在尝试在我的 iOS 应用程序上使用用户位置。该应用程序适用于 iOS 7,但不适用于 iOS 8。

我都试过了。看了一堆教程,我知道在 iOS 8 中我们需要调用 requestWhenInUseAuthorization 方法并将 NSLocationWhenInUseUsageDescription 键添加到 Info.plist 中。

但它仍然无法正常工作,它没有征求用户的许可,我正在真实设备(运行 iOS 8.1.x 的 iPhone 5c)中进行测试。我多次尝试重新安装该应用程序。

这些是我为测试这个东西而创建的一个非常非常小的项目的代码。

我的ViewController.m

#import "ViewController.h"

#import <CoreLocation/CoreLocation.h>

@interface ViewController () <CLLocationManagerDelegate>

@property (strong, nonatomic) CLLocationManager *locationManager;

@end

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];

self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;

self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
self.locationManager.distanceFilter = kCLHeadingFilterNone;

if ([self.locationManager respondsToSelector:@selector(requestWhenInUseAuthorization)]) {
NSLog(@"Pôde chamar o método"); // It could call the method
[self.locationManager requestWhenInUseAuthorization];
}

// [self.locationManager startUpdatingLocation];

}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

#pragma mark - CLLocationManagerDelegate

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations {
NSLog(@"Atualizou Localização para: %@", [locations lastObject]); // 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) {
[self.locationManager startUpdatingLocation];
}
}

@end

我的信息.plist

<?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>

有人知道如何解决这个问题吗?

最佳答案

NSLocationAlwaysUsageDescriptionNSLocationWhenInUseUsageDescription 添加到您的 Info.plist。然后您可以为每个值提供 AlertView 文本。

位置管理器将查看这些字段中的文本以在 AlertView 中进行提示。

关于iOS 8.1 CoreLocationManager requestWhenInUseAuthorization 不提示 AlertView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28942516/

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