iOS9 添加定位功能后,启动应用没有出现允许开启定位权限的通知,或者出现权限通知后,自动消失的解决办法 - 家柱

来源:互联网 发布:仅限数据连接怎么取消 编辑:程序博客网 时间:2024/05/17 09:12

iOS9 添加定位功能后,启动应用没有出现允许开启定位权限的通知,或者出现权限通知后,自动消失的解决办法 - 家柱

碰到了在添加定位功能后,允许定位权限通知偶尔出现,出现后又快速消失的情况,经过一番了解,解决办法如下:在AppDelegate.m的
#import "AppDelegate.h"#import <CoreLocation/CoreLocation.h>@interface AppDelegate () <CLLocationManagerDelegate>@property(nonatomic) CLLocationManager *locationManager;@end  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    // Override point for customization after application launch.    [UIApplication sharedApplication].idleTimerDisabled = YES;    self.locationManager = [[CLLocationManager alloc] init];    self.locationManager.delegate = self;    return YES;}  
// CLLocationManagerDelegate 代理方法- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status{    switch (status) {        case kCLAuthorizationStatusNotDetermined:            if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {                [self.locationManager requestWhenInUseAuthorization];//NSLocationWhenInUseDescription                [self.locationManager requestAlwaysAuthorization];//NSLocationAlwaysUsageDescriptionion            }            break;        default:            break;    }}
同时,在info.plist中,添加NSLocationWhenInUseDescription(Boolean)// 允许应用在前台定位NSLocationAlwaysUsageDescription(Boolean)// 允许应用在后台定位两个都添加默认是第一个。如果是允许程序在后台定位,打开Project->Capabilities->Background Modes,勾选Location updates选项。
0 0
原创粉丝点击