风控系统需要我们客户端提供用户的标准体系国家码,用于定位用户的国家信息。我们使用系统的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:@"经度:%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加油~
网友评论