zoukankan      html  css  js  c++  java
  • 实现一进入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;

        }

    }

  • 相关阅读:
    字符串套餐(更新中)
    洛谷P4145 上帝造题的七分钟2 / 花神游历各国(重题:洛谷SP2713 GSS4
    [AHOI2013]作业
    我的配置
    [HAOI2006]受欢迎的牛
    洛谷P1456Monkey King
    洛谷P2331[SCOI2005]最大子矩阵
    如何更换博客背景
    洛谷P2419 [USACO08JAN]牛大赛Cow Contest
    JS正则表达式验证数字
  • 原文地址:https://www.cnblogs.com/liaolijun/p/6943913.html
Copyright © 2011-2022 走看看