From 7b02207537d35bfa1714bf8beafc921f717d100a Mon Sep 17 00:00:00 2001 From: 单军华 Date: Wed, 11 Jul 2018 10:47:42 +0800 Subject: [PATCH] 首次上传 --- screendisplay/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZLocationManager.m | 89 ++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 89 insertions(+), 0 deletions(-) diff --git a/screendisplay/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZLocationManager.m b/screendisplay/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZLocationManager.m new file mode 100644 index 0000000..cf9b8ff --- /dev/null +++ b/screendisplay/Pods/TZImagePickerController/TZImagePickerController/TZImagePickerController/TZLocationManager.m @@ -0,0 +1,89 @@ +// +// TZLocationManager.m +// TZImagePickerController +// +// Created by ������ on 2017/06/03. +// Copyright �� 2017��� ������. All rights reserved. +// ��������������� + +#import "TZLocationManager.h" +#import "TZImagePickerController.h" + +@interface TZLocationManager ()<CLLocationManagerDelegate> +@property (nonatomic, strong) CLLocationManager *locationManager; +/// ���������������������block +@property (nonatomic, copy) void (^successBlock)(NSArray<CLLocation *> *); +/// ���������������������block +@property (nonatomic, copy) void (^geocodeBlock)(NSArray *geocodeArray); +/// ���������������������block +@property (nonatomic, copy) void (^failureBlock)(NSError *error); +@end + +@implementation TZLocationManager + ++ (instancetype)manager { + static TZLocationManager *manager; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + manager = [[self alloc] init]; + manager.locationManager = [[CLLocationManager alloc] init]; + manager.locationManager.delegate = manager; + if (iOS8Later) { + [manager.locationManager requestWhenInUseAuthorization]; + } + }); + return manager; +} + +- (void)startLocation { + [self startLocationWithSuccessBlock:nil failureBlock:nil geocoderBlock:nil]; +} + +- (void)startLocationWithSuccessBlock:(void (^)(NSArray<CLLocation *> *))successBlock failureBlock:(void (^)(NSError *error))failureBlock { + [self startLocationWithSuccessBlock:successBlock failureBlock:failureBlock geocoderBlock:nil]; +} + +- (void)startLocationWithGeocoderBlock:(void (^)(NSArray *geocoderArray))geocoderBlock { + [self startLocationWithSuccessBlock:nil failureBlock:nil geocoderBlock:geocoderBlock]; +} + +- (void)startLocationWithSuccessBlock:(void (^)(NSArray<CLLocation *> *))successBlock failureBlock:(void (^)(NSError *error))failureBlock geocoderBlock:(void (^)(NSArray *geocoderArray))geocoderBlock { + [self.locationManager startUpdatingLocation]; + _successBlock = successBlock; + _geocodeBlock = geocoderBlock; + _failureBlock = failureBlock; +} + +#pragma mark - CLLocationManagerDelegate + +/// ��������������������������������� +- (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray<CLLocation *> *)locations { + [manager stopUpdatingLocation]; + + if (_successBlock) { + _successBlock(locations); + } + + if (_geocodeBlock && locations.count) { + CLGeocoder *geocoder = [[CLGeocoder alloc] init]; + [geocoder reverseGeocodeLocation:[locations firstObject] completionHandler:^(NSArray *array, NSError *error) { + self->_geocodeBlock(array); + }]; + } +} + +/// ������������������������ +- (void)locationManager:(CLLocationManager *)manager didFailWithError:(NSError *)error { + NSLog(@"������������, ������: %@",error); + switch([error code]) { + case kCLErrorDenied: { // ��������������������������� + + } break; + default: break; + } + if (_failureBlock) { + _failureBlock(error); + } +} + +@end -- Gitblit v1.8.0