实现一进入APP就授权定位
Posted 廖利君
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了实现一进入APP就授权定位相关的知识,希望对你有一定的参考价值。
1、导入CoreLocation.frameWork
2,到Plist文件中增加:
NSLocationWhenInUseDescription//使用app时是否允许app使用定位的提示语
NSLocationAlwaysUsageDescription//不使用app时是否允许app使用定位的提示语
3,在AppDelegate.h中添加
#import <CoreLocation/CoreLocation.h>
@interface AppDelegate : NSObject <CLLocationManagerDelegate> //协议
@property(nonatomic) CLLocationManager *locationManager;
@end
4,在AppDelegate.m中添加
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
[UIApplication sharedApplication].idleTimerDisabled = TRUE;
self.locationManager = [[CLLocationManager alloc] init];
self.locationManager.delegate = self;
return YES;
}
- (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatus:(CLAuthorizationStatus)status
{
switch (status) {
case kCLAuthorizationStatusNotDetermined:
if ([self.locationManager respondsToSelector:@selector(requestAlwaysAuthorization)]) {
[self.locationManager requestWhenInUseAuthorization]; //NSLocationWhenInUseDescription
[self.locationManager requestAlwaysAuthorization];
}
break;
default:
break;
}
}
以上是关于实现一进入APP就授权定位的主要内容,如果未能解决你的问题,请参考以下文章