2018筆記——國家碼

風控系統(tǒng)需要我們客戶端提供用戶的標準體系國家碼,用于定位用戶的國家信息。我們使用系統(tǒng)的API來完成。

第一步:Target-Build Phases -Link Binary with Libraries添加CoreLocation.framework

第二步:前往info.plist文件中,添加Privacy - Location When In Use Usage Description,添加對應的描述。

第三步:編碼

#import "ViewController.h"

#import <CoreLocation/CoreLocation.h>

@interface ViewController ()<CLLocationManagerDelegate>

/**

*  manager

**/

@property (nonatomic, strong) CLLocationManager *manager;

@end

@implementation ViewController

- (void)viewDidLoad {

    [super viewDidLoad];

    self.manager = [[CLLocationManager alloc]init];

    self.manager.delegate = self;//代理方法

    self.manager.distanceFilter = kCLLocationAccuracyBest;//精確度

}

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event

{

    [self.manager requestWhenInUseAuthorization];

    [self.manager startUpdatingLocation];

}

- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations

{

    CLLocation *location = [locations firstObject];

    NSString *locationInfo = [NSString stringWithFormat:@"經(jīng)度:%lf 緯度:%lf",location.coordinate.longitude,location.coordinate.latitude];

    NSLog(@"%@",locationInfo);

    CLGeocoder *geo = [CLGeocoder new];

    [geo reverseGeocodeLocation:location completionHandler:^(NSArray<CLPlacemark *> * _Nullable placemarks, NSError * _Nullable error) {

        CLPlacemark *pl = [placemarks firstObject];

        NSLog(@"address:%@",pl.name);//地址信息

        NSLog(@"addressDic:%@",pl.ISOcountryCode);//國家編碼

    }];

    [manager stopUpdatingLocation];

}

看一下打印臺的信息:

屏幕快照 2018-05-03 下午3.17.00.png

加油~

?著作權歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容