From e4b14860a1c38f4be8bcc9179f42622874d0d6e8 Mon Sep 17 00:00:00 2001 From: Eugene Antropov Date: Wed, 12 Mar 2014 11:47:59 +0400 Subject: [PATCH 01/16] Fix crash with no founded geo points --- Classes/ios/YandexGeocoder.m | 209 ++++++++++++++++++++--------------- 1 file changed, 118 insertions(+), 91 deletions(-) diff --git a/Classes/ios/YandexGeocoder.m b/Classes/ios/YandexGeocoder.m index 9f10ef1..90f94e4 100644 --- a/Classes/ios/YandexGeocoder.m +++ b/Classes/ios/YandexGeocoder.m @@ -7,13 +7,13 @@ @interface YandexGeocoder () -- (void)makeRequestWithParams:(NSMutableDictionary *)params success:(void (^)(AFHTTPRequestOperation *operation, id responseObject, NSDictionary *places))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure owner:(id)owner; +- (void) makeRequestWithParams: (NSMutableDictionary*) params success: (void (^)(AFHTTPRequestOperation* operation, id responseObject, NSDictionary* places)) success failure: (void (^)(AFHTTPRequestOperation* operation, NSError* error)) failure owner: (id) owner; -- (NSMutableDictionary *)convertResponse:(id)responseObject; +- (NSMutableDictionary*) convertResponse: (id) responseObject; -- (double)radiansWithDistance:(double)meters; +- (double) radiansWithDistance: (double) meters; -@property(readonly, strong) YandexGeocoderClient *client; +@property(readonly, strong) YandexGeocoderClient* client; @end @@ -21,26 +21,30 @@ @implementation YandexGeocoder { } + @synthesize client = _client; /** Singleton * * @return id */ -+ (id)sharedInstance ++ (id) sharedInstance { - static YandexGeocoder *sharedInstance = nil; + static YandexGeocoder* sharedInstance = nil; static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - sharedInstance = [[self alloc] init]; - }); + dispatch_once( + &onceToken, ^ + { + sharedInstance = [[self alloc] init]; + }); return sharedInstance; } -- (id)init +- (id) init { - if (self = [super init]) { - _client = [[YandexGeocoderClient alloc] initWithBaseURL:[NSURL URLWithString:kYandexGeocoderBaseUrl]]; + if (self = [super init]) + { + _client = [[YandexGeocoderClient alloc] initWithBaseURL: [NSURL URLWithString: kYandexGeocoderBaseUrl]]; } return self; } @@ -55,28 +59,38 @@ - (id)init * @param params GET-parameters * @param delegate Delegate than will be notified upon request completion */ -- (void)makeRequestWithParams:(NSMutableDictionary *)params - success:(void (^)(AFHTTPRequestOperation *operation, id responseObject, NSDictionary *places))success - failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure - owner:(id)owner +- (void) makeRequestWithParams: (NSMutableDictionary*) params + success: (void (^)(AFHTTPRequestOperation* operation, id responseObject, NSDictionary* places)) success + failure: (void (^)(AFHTTPRequestOperation* operation, NSError* error)) failure + owner: (id) owner { params[@"sco"] = @"longlat"; //coordinates order params[@"format"] = @"json"; - if (params[@"lang"] == nil) { + if (params[@"lang"] == nil) + { params[@"lang"] = [[NSLocale currentLocale] localeIdentifier]; } - [self.client getPath:@"1.x/" delegate:owner parameters:params success:^(AFHTTPRequestOperation *operation, id responseObject) - { + [self.client getPath: @"1.x/" delegate: owner parameters: params + success: ^(AFHTTPRequestOperation* operation, id responseObject) + { #ifdef DDLogInfo DDLogInfo(@"Yandex Geocoder finished"); #else - NSLog(@"Yandex Geocoder finished"); + NSLog(@"Yandex Geocoder finished"); #endif - NSMutableDictionary *places = [self convertResponse:responseObject]; - success(operation, responseObject, places); - } failure:^(AFHTTPRequestOperation *operation, NSError *error) + NSMutableDictionary* places = [self convertResponse: responseObject]; + if (places.count > 0) + { + success(operation, responseObject, places); + } + else + { + failure(operation, [NSError errorWithDomain: @"com.yandex.geocode" code: 404 + userInfo: @{@"error" : @"Can't find places"}]); + } + } failure: ^(AFHTTPRequestOperation* operation, NSError* error) { #ifdef DDLogError DDLogError(@"Yandex Geocoder failed"); @@ -90,9 +104,9 @@ - (void)makeRequestWithParams:(NSMutableDictionary *)params /** Cancels all requests associated with given delegate * */ -- (void)cancelAllRequestsForDelegate:(id)delegate +- (void) cancelAllRequestsForDelegate: (id) delegate { - [self.client cancelAllOperationsForDelegate:delegate]; + [self.client cancelAllOperationsForDelegate: delegate]; } /** Converts response to more simple structure @@ -100,18 +114,21 @@ - (void)cancelAllRequestsForDelegate:(id)delegate * @param responseObject JSON response * @return Simplified response */ -- (NSMutableDictionary *)convertResponse:(id)responseObject +- (NSMutableDictionary*) convertResponse: (id) responseObject { - NSMutableDictionary *result = [NSMutableDictionary dictionary]; + NSMutableDictionary* result = [NSMutableDictionary dictionary]; - result[@"total"] = responseObject[@"response"][@"GeoObjectCollection"][@"metaDataProperty"][@"GeocoderResponseMetaData"][@"found"]; + result[@"total"] = responseObject[@"response"][@"GeoObjectCollection"][@"metaDataProperty"][@"GeocoderResponseMetaData"][@"found"] ?: @""; - NSMutableArray *places = [NSMutableArray array]; + NSMutableArray* places = [NSMutableArray array]; - [(NSArray *) responseObject[@"response"][@"GeoObjectCollection"][@"featureMember"] enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) + if (responseObject[@"response"][@"GeoObjectCollection"][@"featureMember"]) { - [places addObject:obj[@"GeoObject"]]; - }]; + [(NSArray*) responseObject[@"response"][@"GeoObjectCollection"][@"featureMember"] enumerateObjectsUsingBlock: ^(id obj, NSUInteger idx, BOOL* stop) + { + [places addObject: obj[@"GeoObject"]]; + }]; + } result[@"places"] = places; @@ -129,7 +146,7 @@ - (NSMutableDictionary *)convertResponse:(id)responseObject * @param meters Distance in meters * @return radians */ -- (double)radiansWithDistance:(double)meters +- (double) radiansWithDistance: (double) meters { return meters / kYandexGeocoderEarthRadius; } @@ -139,10 +156,11 @@ - (double)radiansWithDistance:(double)meters * @param object Place item returned by convertResponse: * @return CLLocation */ -+ (CLLocation *)locationFromObject:(NSDictionary *)object ++ (CLLocation*) locationFromObject: (NSDictionary*) object { - NSArray *coords = [(NSString *)object[@"Point"][@"pos"] componentsSeparatedByString:@" "]; - CLLocation *location = [[CLLocation alloc] initWithLatitude:[(NSString *)coords[1] doubleValue] longitude:[(NSString *)coords[0] doubleValue]]; + NSArray* coords = [(NSString*) object[@"Point"][@"pos"] componentsSeparatedByString: @" "]; + CLLocation* location = [[CLLocation alloc] initWithLatitude: [(NSString*) coords[1] doubleValue] + longitude: [(NSString*) coords[0] doubleValue]]; return location; } @@ -151,7 +169,7 @@ + (CLLocation *)locationFromObject:(NSDictionary *)object * @param object Place item returned by convertResponse: * @return Place title */ -+ (NSString *)titleFromObject:(NSDictionary *)object ++ (NSString*) titleFromObject: (NSDictionary*) object { return object[@"metaDataProperty"][@"GeocoderMetaData"][@"text"]; } @@ -161,18 +179,20 @@ + (NSString *)titleFromObject:(NSDictionary *)object * @param object Place item returned by convertResponse: * @return Place city */ -+ (NSString *)cityFromObject:(NSDictionary *)object ++ (NSString*) cityFromObject: (NSDictionary*) object { - NSArray *paths = @[ + NSArray* paths = @[ @"metaDataProperty.GeocoderMetaData.AddressDetails.Country.AdministrativeArea.Locality.LocalityName", @"metaDataProperty.GeocoderMetaData.AddressDetails.Country.Locality.LocalityName", @"metaDataProperty.GeocoderMetaData.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName" ]; - NSString *city; - for (int i = 0; i < paths.count; i++) { - city = [object valueForKeyPath:paths[i]]; - if (city) { + NSString* city; + for (int i = 0; i < paths.count; i++) + { + city = [object valueForKeyPath: paths[i]]; + if (city) + { break; } } @@ -185,7 +205,7 @@ + (NSString *)cityFromObject:(NSDictionary *)object * @param object Place item returned by convertResponse: * @return Place type */ -+ (NSString *)placeTypeFromObject:(NSDictionary *)object ++ (NSString*) placeTypeFromObject: (NSDictionary*) object { return object[@"metaDataProperty"][@"GeocoderMetaData"][@"kind"]; } @@ -199,13 +219,14 @@ + (NSString *)placeTypeFromObject:(NSDictionary *)object * @param longitude Longitude * @param delegate Delegate */ -- (void)reversedGeocodingForLatitude:(double)latitude - longitude:(double)longitude - success:(void (^)(AFHTTPRequestOperation *operation, id responseObject, NSDictionary *places))success - failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure - owner:(id)owner +- (void) reversedGeocodingForLatitude: (double) latitude + longitude: (double) longitude + success: (void (^)(AFHTTPRequestOperation* operation, id responseObject, NSDictionary* places)) success + failure: (void (^)(AFHTTPRequestOperation* operation, NSError* error)) failure + owner: (id) owner { - [self reversedGeocodingForLatitude:latitude longitude:longitude language:nil kind:nil success:success failure:failure owner:owner]; + [self reversedGeocodingForLatitude: latitude longitude: longitude language: nil kind: nil success: success + failure: failure owner: owner]; } /** Get list of places at point @@ -215,13 +236,15 @@ - (void)reversedGeocodingForLatitude:(double)latitude * @param language Language Code * @param delegate Delegate */ -- (void)reversedGeocodingForLatitude:(double)latitude - longitude:(double)longitude - language:(NSString *)language - success:(void (^)(AFHTTPRequestOperation *operation, id responseObject, NSDictionary *places))success - failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure - owner:(id)owner { - [self reversedGeocodingForLatitude:latitude longitude:longitude language:language kind:nil success:success failure:failure owner:owner]; +- (void) reversedGeocodingForLatitude: (double) latitude + longitude: (double) longitude + language: (NSString*) language + success: (void (^)(AFHTTPRequestOperation* operation, id responseObject, NSDictionary* places)) success + failure: (void (^)(AFHTTPRequestOperation* operation, NSError* error)) failure + owner: (id) owner +{ + [self reversedGeocodingForLatitude: latitude longitude: longitude language: language kind: nil success: success + failure: failure owner: owner]; } /** Get list of places at point @@ -232,29 +255,32 @@ - (void)reversedGeocodingForLatitude:(double)latitude * @param kind (house, street, metro, district, locality) * @param delegate Delegate */ -- (void)reversedGeocodingForLatitude:(double)latitude - longitude:(double)longitude - language:(NSString *)language - kind:(NSString *)kind - success:(void (^)(AFHTTPRequestOperation *operation, id responseObject, NSDictionary *places))success - failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure - owner:(id)owner { +- (void) reversedGeocodingForLatitude: (double) latitude + longitude: (double) longitude + language: (NSString*) language + kind: (NSString*) kind + success: (void (^)(AFHTTPRequestOperation* operation, id responseObject, NSDictionary* places)) success + failure: (void (^)(AFHTTPRequestOperation* operation, NSError* error)) failure + owner: (id) owner +{ #ifdef DDLogInfo DDLogInfo(@"Reverse geocoding: lat %f, lng %f", latitude, longitude); #else NSLog(@"Reverse geocoding: lat %f, lng %f", latitude, longitude); #endif - NSMutableDictionary *params = [@{ - @"geocode": [NSString stringWithFormat:@"%.07f,%.07f", longitude, latitude], + NSMutableDictionary* params = [@{ + @"geocode" : [NSString stringWithFormat: @"%.07f,%.07f", longitude, latitude], } mutableCopy]; - if (language != nil) { + if (language != nil) + { params[@"lang"] = language; } - if (kind != nil) { + if (kind != nil) + { params[@"kind"] = kind; } - [self makeRequestWithParams:params success:success failure:failure owner:owner]; + [self makeRequestWithParams: params success: success failure: failure owner: owner]; } /** Get list of places for address @@ -262,18 +288,18 @@ - (void)reversedGeocodingForLatitude:(double)latitude * @param address Query string * @param address delegate Delegate */ -- (void)forwardGeocoding:(NSString *)address - success:(void (^)(AFHTTPRequestOperation *operation, id responseObject, NSDictionary *places))success - failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure - owner:(id)owner +- (void) forwardGeocoding: (NSString*) address + success: (void (^)(AFHTTPRequestOperation* operation, id responseObject, NSDictionary* places)) success + failure: (void (^)(AFHTTPRequestOperation* operation, NSError* error)) failure + owner: (id) owner { #ifdef DDLogInfo DDLogInfo(@"Forward geocoding: %@", address); #else NSLog(@"Forward geocoding: %@", address); #endif - NSMutableDictionary *params = [@{@"geocode": address} mutableCopy]; - [self makeRequestWithParams:params success:success failure:failure owner:owner]; + NSMutableDictionary* params = [@{@"geocode" : address} mutableCopy]; + [self makeRequestWithParams: params success: success failure: failure owner: owner]; } /** Get list of places for address @@ -284,33 +310,34 @@ - (void)forwardGeocoding:(NSString *)address * @param radius Radius of the bounding area * @param limitToBounds YES - limit search to bounding area, NO - don't limit, but return results within the bounding area first */ -- (void)forwardGeocoding:(NSString *)address - limitCenterLat:(double)limitCenterLat - limitCenterLng:(double)limitCenterLng - radius:(double)radius - limitToBounds:(BOOL)limitToBounds - language:(NSString *)language - success:(void (^)(AFHTTPRequestOperation *operation, id responseObject, NSDictionary *places))success - failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure - owner:(id)owner +- (void) forwardGeocoding: (NSString*) address + limitCenterLat: (double) limitCenterLat + limitCenterLng: (double) limitCenterLng + radius: (double) radius + limitToBounds: (BOOL) limitToBounds + language: (NSString*) language + success: (void (^)(AFHTTPRequestOperation* operation, id responseObject, NSDictionary* places)) success + failure: (void (^)(AFHTTPRequestOperation* operation, NSError* error)) failure + owner: (id) owner { #ifdef DDLogInfo DDLogInfo(@"Forward geocoding: %@, lat %f, lng %f, rad %f, limit %d", address, limitCenterLat, limitCenterLng, radius, limitToBounds); #else NSLog(@"Forward geocoding: %@, lat %f, lng %f, rad %f, limit %d", address, limitCenterLat, limitCenterLng, radius, limitToBounds); #endif - NSMutableDictionary *params = [@{ - @"geocode": address, - @"rspn": limitToBounds ? @"1" : @"0", - @"ll": [NSString stringWithFormat:@"%.07f,%.07f", limitCenterLng, limitCenterLat], - @"spn": [NSString stringWithFormat:@"%.07f", [self radiansWithDistance:radius]] + NSMutableDictionary* params = [@{ + @"geocode" : address, + @"rspn" : limitToBounds ? @"1" : @"0", + @"ll" : [NSString stringWithFormat: @"%.07f,%.07f", limitCenterLng, limitCenterLat], + @"spn" : [NSString stringWithFormat: @"%.07f", [self radiansWithDistance: radius]] } mutableCopy]; - if (language != nil) { + if (language != nil) + { params[@"lang"] = language; } - [self makeRequestWithParams:params success:success failure:failure owner:owner]; + [self makeRequestWithParams: params success: success failure: failure owner: owner]; } @end \ No newline at end of file From 4d9a4fa3aa6be42916b3d75516994ff983e69e48 Mon Sep 17 00:00:00 2001 From: sotskiy Date: Fri, 8 Aug 2014 21:15:17 +0400 Subject: [PATCH 02/16] Going to move project to AFNetworking 2.0 --- YandexGeocoder.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/YandexGeocoder.podspec b/YandexGeocoder.podspec index f30d95b..96d9a92 100644 --- a/YandexGeocoder.podspec +++ b/YandexGeocoder.podspec @@ -6,9 +6,9 @@ Pod::Spec.new do |s| s.license = 'MIT' s.author = { "Mikhail Kuznetsov" => "strelok.ru@gmail.com" } s.source = { :git => "https://github.com/exister/YandexGeocoder.git", :tag => "0.0.5" } - s.platform = :ios, '5.0' + s.platform = :ios, '7.0' s.source_files = 'Classes/**/*.{h,m}' s.requires_arc = true s.weak_frameworks = 'CoreLocation' - s.dependency 'AFNetworking', '~> 1.3.0' + s.dependency 'AFNetworking' end From 0eccc69457881330f266fab05f6fba156fb4fb1d Mon Sep 17 00:00:00 2001 From: sotskiy Date: Sat, 9 Aug 2014 00:11:17 +0400 Subject: [PATCH 03/16] Moved to AFNetworking 2.x --- Classes/ios/YandexGeocoder.h | 2 +- Classes/ios/YandexGeocoder.m | 2 +- Classes/ios/YandexGeocoderClient.h | 9 ++++-- Classes/ios/YandexGeocoderClient.m | 29 +++++++++---------- Project/YandexGeocoderExample/Podfile | 4 +-- .../project.pbxproj | 11 +++---- .../YandexGeocoderExample/YGViewController.h | 2 +- .../YandexGeocoderExample/YGViewController.m | 25 +++++++++------- YandexGeocoder.podspec | 6 ++-- 9 files changed, 49 insertions(+), 41 deletions(-) diff --git a/Classes/ios/YandexGeocoder.h b/Classes/ios/YandexGeocoder.h index 4430d06..6cc5ee4 100644 --- a/Classes/ios/YandexGeocoder.h +++ b/Classes/ios/YandexGeocoder.h @@ -2,7 +2,7 @@ #import #import "AFNetworking.h" -#define kYandexGeocoderBaseUrl @"http://geocode-maps.yandex.ru" +#define kYandexGeocoderBaseUrl @"http://geocode-maps.yandex.ru/" #define kYandexGeocoderEarthRadius 6371000.01 @class YandexGeocoderClient; diff --git a/Classes/ios/YandexGeocoder.m b/Classes/ios/YandexGeocoder.m index 90f94e4..e457d52 100644 --- a/Classes/ios/YandexGeocoder.m +++ b/Classes/ios/YandexGeocoder.m @@ -44,7 +44,7 @@ - (id) init { if (self = [super init]) { - _client = [[YandexGeocoderClient alloc] initWithBaseURL: [NSURL URLWithString: kYandexGeocoderBaseUrl]]; + _client = [[YandexGeocoderClient alloc] initWithBaseURL: kYandexGeocoderBaseUrl]; } return self; } diff --git a/Classes/ios/YandexGeocoderClient.h b/Classes/ios/YandexGeocoderClient.h index 1b35896..f4fde44 100644 --- a/Classes/ios/YandexGeocoderClient.h +++ b/Classes/ios/YandexGeocoderClient.h @@ -2,10 +2,15 @@ #import "AFNetworking.h" #import "YandexGeocoder.h" -@class AFHTTPRequestOperation; +@interface YandexGeocoderClient : NSObject +{ + AFHTTPRequestOperationManager *_operationManager; + NSString *_baseUrl; +} + +- (id)initWithBaseURL:(NSString *)url; -@interface YandexGeocoderClient : AFHTTPClient - (void)getPath:(NSString *)path delegate:(id)delegate parameters:(NSDictionary *)parameters success:(void (^)(AFHTTPRequestOperation *, id))success failure:(void (^)(AFHTTPRequestOperation *, NSError *))failure; - (void)cancelAllOperationsForDelegate:(id)delegate; diff --git a/Classes/ios/YandexGeocoderClient.m b/Classes/ios/YandexGeocoderClient.m index c962bcf..ed03b38 100644 --- a/Classes/ios/YandexGeocoderClient.m +++ b/Classes/ios/YandexGeocoderClient.m @@ -13,16 +13,15 @@ @interface YandexGeocoderClient () @end @implementation YandexGeocoderClient -{ - -} -- (id)initWithBaseURL:(NSURL *)url +- (id)initWithBaseURL:(NSString *)url { - self = [super initWithBaseURL:url]; + self = [super init]; if (self) { - [self registerHTTPOperationClass:[AFJSONRequestOperation class]]; - [self setDefaultHeader:@"Accept" value:@"application/json"]; + _operationManager = [AFHTTPRequestOperationManager manager]; + _operationManager.requestSerializer = [AFHTTPRequestSerializer serializer]; + [_operationManager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"]; + _baseUrl = url; } return self; @@ -38,15 +37,13 @@ - (id)initWithBaseURL:(NSURL *)url */ - (void)getPath:(NSString *)path delegate:(id)delegate parameters:(NSDictionary *)parameters success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure { - NSURLRequest *request = [self requestWithMethod:@"GET" path:path parameters:parameters]; - - NSLog(@"%@", request.URL); - - AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure]; - + + AFHTTPRequestOperation *operation = [_operationManager GET:[_baseUrl stringByAppendingString:path] + parameters:parameters + success:success + failure:failure]; + objc_setAssociatedObject(operation, &kGeocodingOperationDelegateObjectKey, delegate, OBJC_ASSOCIATION_ASSIGN); - - [self enqueueHTTPRequestOperation:operation]; } /** Cancels all operations associated with delegate @@ -55,7 +52,7 @@ - (void)getPath:(NSString *)path delegate:(id)delegate parameters:(NSDictionary */ - (void)cancelAllOperationsForDelegate:(id)delegate { - for (NSOperation *operation in [self.operationQueue operations]) { + for (NSOperation *operation in [_operationManager.operationQueue operations]) { if (![operation isKindOfClass:[AFHTTPRequestOperation class]]) { continue; } diff --git a/Project/YandexGeocoderExample/Podfile b/Project/YandexGeocoderExample/Podfile index a8316ab..929b8ad 100644 --- a/Project/YandexGeocoderExample/Podfile +++ b/Project/YandexGeocoderExample/Podfile @@ -1,3 +1,3 @@ -platform :ios, '5.0' +platform :ios, '6.0' -pod 'YandexGeocoder', :local => "../../../YandexGeocoder" \ No newline at end of file +pod 'YandexGeocoder', :path => "../../../YandexGeocoder" diff --git a/Project/YandexGeocoderExample/YandexGeocoderExample.xcodeproj/project.pbxproj b/Project/YandexGeocoderExample/YandexGeocoderExample.xcodeproj/project.pbxproj index d227892..7e3e87a 100644 --- a/Project/YandexGeocoderExample/YandexGeocoderExample.xcodeproj/project.pbxproj +++ b/Project/YandexGeocoderExample/YandexGeocoderExample.xcodeproj/project.pbxproj @@ -7,7 +7,7 @@ objects = { /* Begin PBXBuildFile section */ - 0B8D11E268E54DA79961515C /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ACB122C2242945E5BB2AD89C /* libPods.a */; settings = {}; }; + 0B8D11E268E54DA79961515C /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ACB122C2242945E5BB2AD89C /* libPods.a */; }; 18A039D6168F3DD700550B8D /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 18A039D5168F3DD700550B8D /* UIKit.framework */; }; 18A039D8168F3DD700550B8D /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 18A039D7168F3DD700550B8D /* Foundation.framework */; }; 18A039DA168F3DD700550B8D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 18A039D9168F3DD700550B8D /* CoreGraphics.framework */; }; @@ -59,7 +59,7 @@ 18A03A03168F3DD800550B8D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 18A03A05168F3DD800550B8D /* YandexGeocoderExampleTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = YandexGeocoderExampleTests.h; sourceTree = ""; }; 18A03A06168F3DD800550B8D /* YandexGeocoderExampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = YandexGeocoderExampleTests.m; sourceTree = ""; }; - ACB122C2242945E5BB2AD89C /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = libPods.a; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; + ACB122C2242945E5BB2AD89C /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; F18AAE6E4FB44190B08030B7 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = SOURCE_ROOT; }; /* End PBXFileReference section */ @@ -226,8 +226,6 @@ mainGroup = 18A039C6168F3DD700550B8D; productRefGroup = 18A039D2168F3DD700550B8D /* Products */; projectDirPath = ""; - projectReferences = ( - ); projectRoot = ""; targets = ( 18A039D0168F3DD700550B8D /* YandexGeocoderExample */, @@ -286,7 +284,6 @@ runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; shellScript = "\"${SRCROOT}/Pods/Pods-resources.sh\"\n"; - showEnvVarsInLog = 1; }; /* End PBXShellScriptBuildPhase section */ @@ -404,6 +401,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "YandexGeocoderExample/YandexGeocoderExample-Prefix.pch"; INFOPLIST_FILE = "YandexGeocoderExample/YandexGeocoderExample-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -416,6 +414,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "YandexGeocoderExample/YandexGeocoderExample-Prefix.pch"; INFOPLIST_FILE = "YandexGeocoderExample/YandexGeocoderExample-Info.plist"; + IPHONEOS_DEPLOYMENT_TARGET = 6.0; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -474,6 +473,7 @@ 18A03A0C168F3DD800550B8D /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 18A03A0D168F3DD800550B8D /* Build configuration list for PBXNativeTarget "YandexGeocoderExampleTests" */ = { isa = XCConfigurationList; @@ -482,6 +482,7 @@ 18A03A0F168F3DD800550B8D /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; diff --git a/Project/YandexGeocoderExample/YandexGeocoderExample/YGViewController.h b/Project/YandexGeocoderExample/YandexGeocoderExample/YGViewController.h index dd1758a..ae7f042 100644 --- a/Project/YandexGeocoderExample/YandexGeocoderExample/YGViewController.h +++ b/Project/YandexGeocoderExample/YandexGeocoderExample/YGViewController.h @@ -10,7 +10,7 @@ #import #import "YandexGeocoder.h" -@interface YGViewController : UIViewController +@interface YGViewController : UIViewController - (IBAction)onQueryToLocations:(id)sender; - (IBAction)onPositionToLocations:(id)sender; diff --git a/Project/YandexGeocoderExample/YandexGeocoderExample/YGViewController.m b/Project/YandexGeocoderExample/YandexGeocoderExample/YGViewController.m index f9f2dc5..6f1db01 100644 --- a/Project/YandexGeocoderExample/YandexGeocoderExample/YGViewController.m +++ b/Project/YandexGeocoderExample/YandexGeocoderExample/YGViewController.m @@ -44,19 +44,11 @@ - (void)didReceiveMemoryWarning // Dispose of any resources that can be recreated. } -- (IBAction)onQueryToLocations:(id)sender { - [self.query resignFirstResponder]; - [[YandexGeocoder sharedInstance] forwardGeocoding:self.query.text delegate:self]; -} - - (IBAction)onPositionToLocations:(id)sender { [self.manager startUpdatingLocation]; } -#pragma mark - YandexGeocoderDelegate -/**@name YandexGeocoderDelegate */ - -- (void)yandexGeocoderRequestFinished:(NSMutableDictionary *)places +- (void)yandexGeocoderRequestFinished:(NSDictionary *)places { self.console.text = places.description; } @@ -66,9 +58,22 @@ - (void)yandexGeocoderRequestFailed self.console.text = @"Geocoding failed"; } +- (IBAction)onQueryToLocations:(id)sender { + [self.query resignFirstResponder]; + [[YandexGeocoder sharedInstance] forwardGeocoding:self.query.text success:^(AFHTTPRequestOperation *operation, id responseObject, NSDictionary *places) { + [self yandexGeocoderRequestFinished:places]; + } failure:^(AFHTTPRequestOperation *operation, NSError *error) { + [self yandexGeocoderRequestFailed]; + } owner:self]; +} + - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { CLLocation *location = locations[0]; - [[YandexGeocoder sharedInstance] reversedGeocodingForLatitude:location.coordinate.latitude longitude:location.coordinate.longitude delegate:self]; + [[YandexGeocoder sharedInstance] reversedGeocodingForLatitude:location.coordinate.latitude longitude:location.coordinate.longitude language:@"EN" kind:@"house" success:^(AFHTTPRequestOperation *operation, id responseObject, NSDictionary *places) { + [self yandexGeocoderRequestFinished:places]; + } failure:^(AFHTTPRequestOperation *operation, NSError *error) { + [self yandexGeocoderRequestFailed]; + } owner:self]; } @end diff --git a/YandexGeocoder.podspec b/YandexGeocoder.podspec index 96d9a92..2662222 100644 --- a/YandexGeocoder.podspec +++ b/YandexGeocoder.podspec @@ -1,12 +1,12 @@ Pod::Spec.new do |s| s.name = "YandexGeocoder" - s.version = "0.0.5" + s.version = "0.1.0" s.summary = "Use Yandex Geocoding API for forward and reversed geocoding." s.homepage = "https://github.com/exister/YandexGeocoder" s.license = 'MIT' s.author = { "Mikhail Kuznetsov" => "strelok.ru@gmail.com" } - s.source = { :git => "https://github.com/exister/YandexGeocoder.git", :tag => "0.0.5" } - s.platform = :ios, '7.0' + s.source = { :git => "https://github.com/exister/YandexGeocoder.git" } + s.platform = :ios, '6.0' s.source_files = 'Classes/**/*.{h,m}' s.requires_arc = true s.weak_frameworks = 'CoreLocation' From 8f35223e03488820272b622dec9e74d2d971b87c Mon Sep 17 00:00:00 2001 From: sotskiy Date: Sun, 22 Feb 2015 08:37:05 +0300 Subject: [PATCH 04/16] Language selection for forward querys --- Classes/ios/YandexGeocoder.h | 6 ++++ Classes/ios/YandexGeocoder.m | 33 ++++++++++++++++--- .../YandexGeocoderExample/YGViewController.m | 2 +- 3 files changed, 36 insertions(+), 5 deletions(-) diff --git a/Classes/ios/YandexGeocoder.h b/Classes/ios/YandexGeocoder.h index 6cc5ee4..a8ecef4 100644 --- a/Classes/ios/YandexGeocoder.h +++ b/Classes/ios/YandexGeocoder.h @@ -22,6 +22,12 @@ - (void)forwardGeocoding:(NSString *)address success:(void (^)(AFHTTPRequestOperation *operation, id responseObject, NSDictionary *places))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure owner:(id)owner; +- (void)forwardGeocoding: (NSString*) address + language: (NSString*) language + success: (void (^)(AFHTTPRequestOperation* operation, id responseObject, NSDictionary* places)) success + failure: (void (^)(AFHTTPRequestOperation* operation, NSError* error)) failure + owner: (id) owner; + - (void)forwardGeocoding:(NSString *)address limitCenterLat:(double)limitCenterLat limitCenterLng:(double)limitCenterLng radius:(double)radius limitToBounds:(BOOL)limitToBounds language:(NSString *)language success:(void (^)(AFHTTPRequestOperation *operation, id responseObject, NSDictionary *places))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure owner:(id)owner; + (CLLocation *)locationFromObject:(NSDictionary *)object; diff --git a/Classes/ios/YandexGeocoder.m b/Classes/ios/YandexGeocoder.m index e457d52..f1b7e9e 100644 --- a/Classes/ios/YandexGeocoder.m +++ b/Classes/ios/YandexGeocoder.m @@ -217,7 +217,7 @@ + (NSString*) placeTypeFromObject: (NSDictionary*) object * * @param latitude Latitude * @param longitude Longitude -* @param delegate Delegate +* @param owner Delegate */ - (void) reversedGeocodingForLatitude: (double) latitude longitude: (double) longitude @@ -234,7 +234,7 @@ - (void) reversedGeocodingForLatitude: (double) latitude * @param latitude Latitude * @param longitude Longitude * @param language Language Code -* @param delegate Delegate +* @param owner Delegate */ - (void) reversedGeocodingForLatitude: (double) latitude longitude: (double) longitude @@ -253,7 +253,7 @@ - (void) reversedGeocodingForLatitude: (double) latitude * @param longitude Longitude * @param language Language Code * @param kind (house, street, metro, district, locality) -* @param delegate Delegate +* @param owner Delegate */ - (void) reversedGeocodingForLatitude: (double) latitude longitude: (double) longitude @@ -286,7 +286,7 @@ - (void) reversedGeocodingForLatitude: (double) latitude /** Get list of places for address * * @param address Query string -* @param address delegate Delegate +* @param owner Delegate */ - (void) forwardGeocoding: (NSString*) address success: (void (^)(AFHTTPRequestOperation* operation, id responseObject, NSDictionary* places)) success @@ -302,6 +302,31 @@ - (void) forwardGeocoding: (NSString*) address [self makeRequestWithParams: params success: success failure: failure owner: owner]; } +/** Get list of places for address + * + * @param address Query string + * @param language Language Code + * @param owner Delegate + */ +- (void) forwardGeocoding: (NSString*) address + language: (NSString*) language + success: (void (^)(AFHTTPRequestOperation* operation, id responseObject, NSDictionary* places)) success + failure: (void (^)(AFHTTPRequestOperation* operation, NSError* error)) failure + owner: (id) owner +{ +#ifdef DDLogInfo + DDLogInfo(@"Forward geocoding: %@", address); +#else + NSLog(@"Forward geocoding: %@", address); +#endif + NSMutableDictionary* params = [@{@"geocode" : address} mutableCopy]; + if (language != nil) + { + params[@"lang"] = language; + } + [self makeRequestWithParams: params success: success failure: failure owner: owner]; +} + /** Get list of places for address * * @param address Query string diff --git a/Project/YandexGeocoderExample/YandexGeocoderExample/YGViewController.m b/Project/YandexGeocoderExample/YandexGeocoderExample/YGViewController.m index 6f1db01..e1c8fb5 100644 --- a/Project/YandexGeocoderExample/YandexGeocoderExample/YGViewController.m +++ b/Project/YandexGeocoderExample/YandexGeocoderExample/YGViewController.m @@ -60,7 +60,7 @@ - (void)yandexGeocoderRequestFailed - (IBAction)onQueryToLocations:(id)sender { [self.query resignFirstResponder]; - [[YandexGeocoder sharedInstance] forwardGeocoding:self.query.text success:^(AFHTTPRequestOperation *operation, id responseObject, NSDictionary *places) { + [[YandexGeocoder sharedInstance] forwardGeocoding:self.query.text language:@"RU" success:^(AFHTTPRequestOperation *operation, id responseObject, NSDictionary *places) { [self yandexGeocoderRequestFinished:places]; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { [self yandexGeocoderRequestFailed]; From 7354afbf62b72462f95fdb282fc58b54dc0e17f4 Mon Sep 17 00:00:00 2001 From: Denis Syrokvash Date: Wed, 18 Jul 2018 19:20:09 +0300 Subject: [PATCH 05/16] updated Podfile syntax --- Project/YandexGeocoderExample/Podfile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Project/YandexGeocoderExample/Podfile b/Project/YandexGeocoderExample/Podfile index 929b8ad..d80f750 100644 --- a/Project/YandexGeocoderExample/Podfile +++ b/Project/YandexGeocoderExample/Podfile @@ -1,3 +1,5 @@ platform :ios, '6.0' -pod 'YandexGeocoder', :path => "../../../YandexGeocoder" +target 'YandexGeocoderExample' do + pod 'YandexGeocoder', :path => "../../../YandexGeocoder" +end From 362a45e95306a85b2f1a694a16b637e9f0f8efe8 Mon Sep 17 00:00:00 2001 From: Denis Syrokvash Date: Wed, 18 Jul 2018 19:23:38 +0300 Subject: [PATCH 06/16] updated project file to be compatible with the latest cocoapods requirements --- .../project.pbxproj | 91 ++++++++++++++++--- .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++ .../xcshareddata/IDEWorkspaceChecks.plist | 8 ++ .../YandexGeocoderExample-Info.plist | 2 +- .../YandexGeocoderExampleTests-Info.plist | 2 +- 5 files changed, 94 insertions(+), 17 deletions(-) create mode 100644 Project/YandexGeocoderExample/YandexGeocoderExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist create mode 100644 Project/YandexGeocoderExample/YandexGeocoderExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist diff --git a/Project/YandexGeocoderExample/YandexGeocoderExample.xcodeproj/project.pbxproj b/Project/YandexGeocoderExample/YandexGeocoderExample.xcodeproj/project.pbxproj index 7e3e87a..d5a4358 100644 --- a/Project/YandexGeocoderExample/YandexGeocoderExample.xcodeproj/project.pbxproj +++ b/Project/YandexGeocoderExample/YandexGeocoderExample.xcodeproj/project.pbxproj @@ -7,7 +7,6 @@ objects = { /* Begin PBXBuildFile section */ - 0B8D11E268E54DA79961515C /* libPods.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ACB122C2242945E5BB2AD89C /* libPods.a */; }; 18A039D6168F3DD700550B8D /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 18A039D5168F3DD700550B8D /* UIKit.framework */; }; 18A039D8168F3DD700550B8D /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 18A039D7168F3DD700550B8D /* Foundation.framework */; }; 18A039DA168F3DD700550B8D /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 18A039D9168F3DD700550B8D /* CoreGraphics.framework */; }; @@ -24,6 +23,7 @@ 18A039FC168F3DD800550B8D /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 18A039D7168F3DD700550B8D /* Foundation.framework */; }; 18A03A04168F3DD800550B8D /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 18A03A02168F3DD800550B8D /* InfoPlist.strings */; }; 18A03A07168F3DD800550B8D /* YandexGeocoderExampleTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 18A03A06168F3DD800550B8D /* YandexGeocoderExampleTests.m */; }; + 59D63140B46791D7A57D3DFB /* libPods-YandexGeocoderExample.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 6004A4317C653E6623589161 /* libPods-YandexGeocoderExample.a */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -59,8 +59,10 @@ 18A03A03168F3DD800550B8D /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 18A03A05168F3DD800550B8D /* YandexGeocoderExampleTests.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = YandexGeocoderExampleTests.h; sourceTree = ""; }; 18A03A06168F3DD800550B8D /* YandexGeocoderExampleTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = YandexGeocoderExampleTests.m; sourceTree = ""; }; + 1E7A40449328FDEC50B080F0 /* Pods-YandexGeocoderExample.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-YandexGeocoderExample.release.xcconfig"; path = "Pods/Target Support Files/Pods-YandexGeocoderExample/Pods-YandexGeocoderExample.release.xcconfig"; sourceTree = ""; }; + 433B28D8B57CD8B20D6B58C2 /* Pods-YandexGeocoderExample.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-YandexGeocoderExample.debug.xcconfig"; path = "Pods/Target Support Files/Pods-YandexGeocoderExample/Pods-YandexGeocoderExample.debug.xcconfig"; sourceTree = ""; }; + 6004A4317C653E6623589161 /* libPods-YandexGeocoderExample.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-YandexGeocoderExample.a"; sourceTree = BUILT_PRODUCTS_DIR; }; ACB122C2242945E5BB2AD89C /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libPods.a; sourceTree = BUILT_PRODUCTS_DIR; }; - F18AAE6E4FB44190B08030B7 /* Pods.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = Pods.xcconfig; path = Pods/Pods.xcconfig; sourceTree = SOURCE_ROOT; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -71,7 +73,7 @@ 18A039D6168F3DD700550B8D /* UIKit.framework in Frameworks */, 18A039D8168F3DD700550B8D /* Foundation.framework in Frameworks */, 18A039DA168F3DD700550B8D /* CoreGraphics.framework in Frameworks */, - 0B8D11E268E54DA79961515C /* libPods.a in Frameworks */, + 59D63140B46791D7A57D3DFB /* libPods-YandexGeocoderExample.a in Frameworks */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -95,7 +97,7 @@ 18A039FF168F3DD800550B8D /* YandexGeocoderExampleTests */, 18A039D4168F3DD700550B8D /* Frameworks */, 18A039D2168F3DD700550B8D /* Products */, - F18AAE6E4FB44190B08030B7 /* Pods.xcconfig */, + EB1777066855ACF2A3338DB9 /* Pods */, ); sourceTree = ""; }; @@ -116,6 +118,7 @@ 18A039D9168F3DD700550B8D /* CoreGraphics.framework */, 18A039F9168F3DD800550B8D /* SenTestingKit.framework */, ACB122C2242945E5BB2AD89C /* libPods.a */, + 6004A4317C653E6623589161 /* libPods-YandexGeocoderExample.a */, ); name = Frameworks; sourceTree = ""; @@ -166,6 +169,15 @@ name = "Supporting Files"; sourceTree = ""; }; + EB1777066855ACF2A3338DB9 /* Pods */ = { + isa = PBXGroup; + children = ( + 433B28D8B57CD8B20D6B58C2 /* Pods-YandexGeocoderExample.debug.xcconfig */, + 1E7A40449328FDEC50B080F0 /* Pods-YandexGeocoderExample.release.xcconfig */, + ); + name = Pods; + sourceTree = ""; + }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -173,10 +185,10 @@ isa = PBXNativeTarget; buildConfigurationList = 18A03A0A168F3DD800550B8D /* Build configuration list for PBXNativeTarget "YandexGeocoderExample" */; buildPhases = ( + D974C309C14D0DAC2452AF51 /* [CP] Check Pods Manifest.lock */, 18A039CD168F3DD700550B8D /* Sources */, 18A039CE168F3DD700550B8D /* Frameworks */, 18A039CF168F3DD700550B8D /* Resources */, - DC0A769216ED4DDFA3244F2D /* Copy Pods Resources */, ); buildRules = ( ); @@ -213,7 +225,7 @@ isa = PBXProject; attributes = { CLASSPREFIX = YG; - LastUpgradeCheck = 0450; + LastUpgradeCheck = 0940; ORGANIZATIONNAME = mkuznetsov; }; buildConfigurationList = 18A039CB168F3DD700550B8D /* Build configuration list for PBXProject "YandexGeocoderExample" */; @@ -271,19 +283,23 @@ shellPath = /bin/sh; shellScript = "# Run the unit tests in this test bundle.\n\"${SYSTEM_DEVELOPER_DIR}/Tools/RunUnitTests\"\n"; }; - DC0A769216ED4DDFA3244F2D /* Copy Pods Resources */ = { + D974C309C14D0DAC2452AF51 /* [CP] Check Pods Manifest.lock */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; files = ( ); inputPaths = ( + "${PODS_PODFILE_DIR_PATH}/Podfile.lock", + "${PODS_ROOT}/Manifest.lock", ); - name = "Copy Pods Resources"; + name = "[CP] Check Pods Manifest.lock"; outputPaths = ( + "$(DERIVED_FILE_DIR)/Pods-YandexGeocoderExample-checkManifestLockResult.txt", ); runOnlyForDeploymentPostprocessing = 0; shellPath = /bin/sh; - shellScript = "\"${SRCROOT}/Pods/Pods-resources.sh\"\n"; + shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; + showEnvVarsInLog = 0; }; /* End PBXShellScriptBuildPhase section */ @@ -351,22 +367,43 @@ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = NO; + ENABLE_STRICT_OBJC_MSGSEND = YES; + ENABLE_TESTABILITY = YES; GCC_C_LANGUAGE_STANDARD = gnu99; GCC_DYNAMIC_NO_PIC = NO; + GCC_NO_COMMON_BLOCKS = YES; GCC_OPTIMIZATION_LEVEL = 0; GCC_PREPROCESSOR_DEFINITIONS = ( "DEBUG=1", "$(inherited)", ); GCC_SYMBOLS_PRIVATE_EXTERN = NO; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 6.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; ONLY_ACTIVE_ARCH = YES; SDKROOT = iphoneos; }; @@ -379,15 +416,35 @@ CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; + CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; + CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_EMPTY_BODY = YES; + CLANG_WARN_ENUM_CONVERSION = YES; + CLANG_WARN_INFINITE_RECURSION = YES; + CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; + CLANG_WARN_SUSPICIOUS_MOVE = YES; + CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; COPY_PHASE_STRIP = YES; + ENABLE_STRICT_OBJC_MSGSEND = YES; GCC_C_LANGUAGE_STANDARD = gnu99; + GCC_NO_COMMON_BLOCKS = YES; + GCC_WARN_64_TO_32_BIT_CONVERSION = YES; GCC_WARN_ABOUT_RETURN_TYPE = YES; + GCC_WARN_UNDECLARED_SELECTOR = YES; GCC_WARN_UNINITIALIZED_AUTOS = YES; + GCC_WARN_UNUSED_FUNCTION = YES; GCC_WARN_UNUSED_VARIABLE = YES; - IPHONEOS_DEPLOYMENT_TARGET = 6.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; OTHER_CFLAGS = "-DNS_BLOCK_ASSERTIONS=1"; SDKROOT = iphoneos; VALIDATE_PRODUCT = YES; @@ -396,12 +453,13 @@ }; 18A03A0B168F3DD800550B8D /* Debug */ = { isa = XCBuildConfiguration; - baseConfigurationReference = F18AAE6E4FB44190B08030B7 /* Pods.xcconfig */; + baseConfigurationReference = 433B28D8B57CD8B20D6B58C2 /* Pods-YandexGeocoderExample.debug.xcconfig */; buildSettings = { GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "YandexGeocoderExample/YandexGeocoderExample-Prefix.pch"; INFOPLIST_FILE = "YandexGeocoderExample/YandexGeocoderExample-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 6.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + PRODUCT_BUNDLE_IDENTIFIER = "com.mkuznetsov.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -409,12 +467,13 @@ }; 18A03A0C168F3DD800550B8D /* Release */ = { isa = XCBuildConfiguration; - baseConfigurationReference = F18AAE6E4FB44190B08030B7 /* Pods.xcconfig */; + baseConfigurationReference = 1E7A40449328FDEC50B080F0 /* Pods-YandexGeocoderExample.release.xcconfig */; buildSettings = { GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "YandexGeocoderExample/YandexGeocoderExample-Prefix.pch"; INFOPLIST_FILE = "YandexGeocoderExample/YandexGeocoderExample-Info.plist"; - IPHONEOS_DEPLOYMENT_TARGET = 6.0; + IPHONEOS_DEPLOYMENT_TARGET = 8.0; + PRODUCT_BUNDLE_IDENTIFIER = "com.mkuznetsov.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -431,6 +490,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "YandexGeocoderExample/YandexGeocoderExample-Prefix.pch"; INFOPLIST_FILE = "YandexGeocoderExampleTests/YandexGeocoderExampleTests-Info.plist"; + PRODUCT_BUNDLE_IDENTIFIER = "com.mkuznetsov.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUNDLE_LOADER)"; WRAPPER_EXTENSION = octest; @@ -448,6 +508,7 @@ GCC_PRECOMPILE_PREFIX_HEADER = YES; GCC_PREFIX_HEADER = "YandexGeocoderExample/YandexGeocoderExample-Prefix.pch"; INFOPLIST_FILE = "YandexGeocoderExampleTests/YandexGeocoderExampleTests-Info.plist"; + PRODUCT_BUNDLE_IDENTIFIER = "com.mkuznetsov.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; TEST_HOST = "$(BUNDLE_LOADER)"; WRAPPER_EXTENSION = octest; diff --git a/Project/YandexGeocoderExample/YandexGeocoderExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Project/YandexGeocoderExample/YandexGeocoderExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Project/YandexGeocoderExample/YandexGeocoderExample.xcodeproj/project.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Project/YandexGeocoderExample/YandexGeocoderExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist b/Project/YandexGeocoderExample/YandexGeocoderExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist new file mode 100644 index 0000000..18d9810 --- /dev/null +++ b/Project/YandexGeocoderExample/YandexGeocoderExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist @@ -0,0 +1,8 @@ + + + + + IDEDidComputeMac32BitWarning + + + diff --git a/Project/YandexGeocoderExample/YandexGeocoderExample/YandexGeocoderExample-Info.plist b/Project/YandexGeocoderExample/YandexGeocoderExample/YandexGeocoderExample-Info.plist index f5e0890..8a34c1e 100644 --- a/Project/YandexGeocoderExample/YandexGeocoderExample/YandexGeocoderExample-Info.plist +++ b/Project/YandexGeocoderExample/YandexGeocoderExample/YandexGeocoderExample-Info.plist @@ -9,7 +9,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - com.mkuznetsov.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundleName diff --git a/Project/YandexGeocoderExample/YandexGeocoderExampleTests/YandexGeocoderExampleTests-Info.plist b/Project/YandexGeocoderExample/YandexGeocoderExampleTests/YandexGeocoderExampleTests-Info.plist index 76ac3df..169b6f7 100644 --- a/Project/YandexGeocoderExample/YandexGeocoderExampleTests/YandexGeocoderExampleTests-Info.plist +++ b/Project/YandexGeocoderExample/YandexGeocoderExampleTests/YandexGeocoderExampleTests-Info.plist @@ -7,7 +7,7 @@ CFBundleExecutable ${EXECUTABLE_NAME} CFBundleIdentifier - com.mkuznetsov.${PRODUCT_NAME:rfc1034identifier} + $(PRODUCT_BUNDLE_IDENTIFIER) CFBundleInfoDictionaryVersion 6.0 CFBundlePackageType From fa8c7bd446fc6032092fd153e2caab3f407df6a4 Mon Sep 17 00:00:00 2001 From: Denis Syrokvash Date: Wed, 18 Jul 2018 19:30:50 +0300 Subject: [PATCH 07/16] Podfile minimum required version updated to 8.0 --- Project/YandexGeocoderExample/Podfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Project/YandexGeocoderExample/Podfile b/Project/YandexGeocoderExample/Podfile index d80f750..49ac827 100644 --- a/Project/YandexGeocoderExample/Podfile +++ b/Project/YandexGeocoderExample/Podfile @@ -1,4 +1,4 @@ -platform :ios, '6.0' +platform :ios, '8.0' target 'YandexGeocoderExample' do pod 'YandexGeocoder', :path => "../../../YandexGeocoder" From 8ef80e142f9c9de346755f55bd772d1025fab592 Mon Sep 17 00:00:00 2001 From: Denis Syrokvash Date: Wed, 18 Jul 2018 19:31:50 +0300 Subject: [PATCH 08/16] podspec updated to match newer AFNetworking requirements (target deployment target ios 8.0) --- YandexGeocoder.podspec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/YandexGeocoder.podspec b/YandexGeocoder.podspec index 2662222..04ae18e 100644 --- a/YandexGeocoder.podspec +++ b/YandexGeocoder.podspec @@ -6,9 +6,9 @@ Pod::Spec.new do |s| s.license = 'MIT' s.author = { "Mikhail Kuznetsov" => "strelok.ru@gmail.com" } s.source = { :git => "https://github.com/exister/YandexGeocoder.git" } - s.platform = :ios, '6.0' + s.platform = :ios, '8.0' s.source_files = 'Classes/**/*.{h,m}' s.requires_arc = true s.weak_frameworks = 'CoreLocation' - s.dependency 'AFNetworking' + s.dependency 'AFNetworking', '~> 3.2' end From 5ae67a4a53a2d7440a03ceca36858a0fa0cf3f09 Mon Sep 17 00:00:00 2001 From: Denis Syrokvash Date: Wed, 18 Jul 2018 19:32:58 +0300 Subject: [PATCH 09/16] workspace support added for project by xcode 9 --- .../project.xcworkspace/contents.xcworkspacedata | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 Project/YandexGeocoderExample/YandexGeocoderExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata diff --git a/Project/YandexGeocoderExample/YandexGeocoderExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/Project/YandexGeocoderExample/YandexGeocoderExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata new file mode 100644 index 0000000..919434a --- /dev/null +++ b/Project/YandexGeocoderExample/YandexGeocoderExample.xcodeproj/project.xcworkspace/contents.xcworkspacedata @@ -0,0 +1,7 @@ + + + + + From 86957404bef59496e1738d7db5901ddb868b0f4d Mon Sep 17 00:00:00 2001 From: Denis Syrokvash Date: Thu, 19 Jul 2018 17:03:42 +0300 Subject: [PATCH 10/16] updated code to support AFNetworking v3.2 --- Classes/ios/YandexGeocoder.h | 47 +++++++++++++++++++++++------- Classes/ios/YandexGeocoder.m | 47 ++++++++++++++++-------------- Classes/ios/YandexGeocoderClient.h | 14 +++++++-- Classes/ios/YandexGeocoderClient.m | 37 +++++++++++------------ 4 files changed, 91 insertions(+), 54 deletions(-) diff --git a/Classes/ios/YandexGeocoder.h b/Classes/ios/YandexGeocoder.h index a8ecef4..a58fad4 100644 --- a/Classes/ios/YandexGeocoder.h +++ b/Classes/ios/YandexGeocoder.h @@ -14,21 +14,46 @@ - (void)cancelAllRequestsForDelegate:(id)delegate; -- (void)reversedGeocodingForLatitude:(double)latitude longitude:(double)longitude success:(void (^)(AFHTTPRequestOperation *operation, id responseObject, NSDictionary *places))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure owner:(id)owner; - -- (void)reversedGeocodingForLatitude:(double)latitude longitude:(double)longitude language:(NSString *)language success:(void (^)(AFHTTPRequestOperation *operation, id responseObject, NSDictionary *places))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure owner:(id)owner; - -- (void)reversedGeocodingForLatitude:(double)latitude longitude:(double)longitude language:(NSString *)language kind:(NSString *)kind success:(void (^)(AFHTTPRequestOperation *operation, id responseObject, NSDictionary *places))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure owner:(id)owner; - -- (void)forwardGeocoding:(NSString *)address success:(void (^)(AFHTTPRequestOperation *operation, id responseObject, NSDictionary *places))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure owner:(id)owner; +- (void)reversedGeocodingForLatitude:(double)latitude + longitude:(double)longitude + success:(void (^)(NSURLSessionDataTask *task, id responseObject, NSDictionary *places))success + failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure + owner:(id)owner; + +- (void)reversedGeocodingForLatitude:(double)latitude + longitude:(double)longitude + language:(NSString *)language + success:(void (^)(NSURLSessionDataTask *task, id responseObject, NSDictionary *places))success + failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure + owner:(id)owner; + +- (void)reversedGeocodingForLatitude:(double)latitude + longitude:(double)longitude + language:(NSString *)language + kind:(NSString *)kind + success:(void (^)(NSURLSessionDataTask *task, id responseObject, NSDictionary *places))success + failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure + owner:(id)owner; + +- (void)forwardGeocoding:(NSString *)address + success:(void (^)(NSURLSessionDataTask *task, id responseObject, NSDictionary *places))success + failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure + owner:(id)owner; - (void)forwardGeocoding: (NSString*) address language: (NSString*) language - success: (void (^)(AFHTTPRequestOperation* operation, id responseObject, NSDictionary* places)) success - failure: (void (^)(AFHTTPRequestOperation* operation, NSError* error)) failure + success: (void (^)(NSURLSessionDataTask *task, id responseObject, NSDictionary* places)) success + failure: (void (^)(NSURLSessionDataTask *task, NSError* error)) failure owner: (id) owner; -- (void)forwardGeocoding:(NSString *)address limitCenterLat:(double)limitCenterLat limitCenterLng:(double)limitCenterLng radius:(double)radius limitToBounds:(BOOL)limitToBounds language:(NSString *)language success:(void (^)(AFHTTPRequestOperation *operation, id responseObject, NSDictionary *places))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure owner:(id)owner; +- (void)forwardGeocoding:(NSString *)address + limitCenterLat:(double)limitCenterLat + limitCenterLng:(double)limitCenterLng + radius:(double)radius + limitToBounds:(BOOL)limitToBounds + language:(NSString *)language + success:(void (^)(NSURLSessionDataTask *task, id responseObject, NSDictionary *places))success + failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure owner:(id)owner; + (CLLocation *)locationFromObject:(NSDictionary *)object; @@ -38,4 +63,4 @@ + (NSString *)placeTypeFromObject:(NSDictionary *)object; -@end \ No newline at end of file +@end diff --git a/Classes/ios/YandexGeocoder.m b/Classes/ios/YandexGeocoder.m index f1b7e9e..14e18fb 100644 --- a/Classes/ios/YandexGeocoder.m +++ b/Classes/ios/YandexGeocoder.m @@ -7,7 +7,10 @@ @interface YandexGeocoder () -- (void) makeRequestWithParams: (NSMutableDictionary*) params success: (void (^)(AFHTTPRequestOperation* operation, id responseObject, NSDictionary* places)) success failure: (void (^)(AFHTTPRequestOperation* operation, NSError* error)) failure owner: (id) owner; +- (void) makeRequestWithParams: (NSMutableDictionary*) params + success: (void (^)(NSURLSessionDataTask *task, id responseObject, NSDictionary* places)) success + failure: (void (^)(NSURLSessionDataTask *task, NSError* error)) failure + owner: (id) owner; - (NSMutableDictionary*) convertResponse: (id) responseObject; @@ -57,11 +60,11 @@ - (id) init * Adds required parameters to each request. * * @param params GET-parameters -* @param delegate Delegate than will be notified upon request completion +* @param owner Delegate than will be notified upon request completion */ - (void) makeRequestWithParams: (NSMutableDictionary*) params - success: (void (^)(AFHTTPRequestOperation* operation, id responseObject, NSDictionary* places)) success - failure: (void (^)(AFHTTPRequestOperation* operation, NSError* error)) failure + success: (void (^)(NSURLSessionDataTask *task, id responseObject, NSDictionary* places)) success + failure: (void (^)(NSURLSessionDataTask *task, NSError* error)) failure owner: (id) owner { params[@"sco"] = @"longlat"; //coordinates order @@ -73,7 +76,7 @@ - (void) makeRequestWithParams: (NSMutableDictionary*) params } [self.client getPath: @"1.x/" delegate: owner parameters: params - success: ^(AFHTTPRequestOperation* operation, id responseObject) + success: ^(NSURLSessionDataTask *task, id responseObject) { #ifdef DDLogInfo DDLogInfo(@"Yandex Geocoder finished"); @@ -83,21 +86,21 @@ - (void) makeRequestWithParams: (NSMutableDictionary*) params NSMutableDictionary* places = [self convertResponse: responseObject]; if (places.count > 0) { - success(operation, responseObject, places); + success(task, responseObject, places); } else { - failure(operation, [NSError errorWithDomain: @"com.yandex.geocode" code: 404 + failure(task, [NSError errorWithDomain: @"com.yandex.geocode" code: 404 userInfo: @{@"error" : @"Can't find places"}]); } - } failure: ^(AFHTTPRequestOperation* operation, NSError* error) + } failure: ^(NSURLSessionDataTask *task, NSError* error) { #ifdef DDLogError DDLogError(@"Yandex Geocoder failed"); #else NSLog(@"Yandex Geocoder failed"); #endif - failure(operation, error); + failure(task, error); }]; } @@ -221,8 +224,8 @@ + (NSString*) placeTypeFromObject: (NSDictionary*) object */ - (void) reversedGeocodingForLatitude: (double) latitude longitude: (double) longitude - success: (void (^)(AFHTTPRequestOperation* operation, id responseObject, NSDictionary* places)) success - failure: (void (^)(AFHTTPRequestOperation* operation, NSError* error)) failure + success: (void (^)(NSURLSessionDataTask *task, id responseObject, NSDictionary* places)) success + failure: (void (^)(NSURLSessionDataTask *task, NSError* error)) failure owner: (id) owner { [self reversedGeocodingForLatitude: latitude longitude: longitude language: nil kind: nil success: success @@ -239,8 +242,8 @@ - (void) reversedGeocodingForLatitude: (double) latitude - (void) reversedGeocodingForLatitude: (double) latitude longitude: (double) longitude language: (NSString*) language - success: (void (^)(AFHTTPRequestOperation* operation, id responseObject, NSDictionary* places)) success - failure: (void (^)(AFHTTPRequestOperation* operation, NSError* error)) failure + success: (void (^)(NSURLSessionDataTask *task, id responseObject, NSDictionary* places)) success + failure: (void (^)(NSURLSessionDataTask *task, NSError* error)) failure owner: (id) owner { [self reversedGeocodingForLatitude: latitude longitude: longitude language: language kind: nil success: success @@ -259,8 +262,8 @@ - (void) reversedGeocodingForLatitude: (double) latitude longitude: (double) longitude language: (NSString*) language kind: (NSString*) kind - success: (void (^)(AFHTTPRequestOperation* operation, id responseObject, NSDictionary* places)) success - failure: (void (^)(AFHTTPRequestOperation* operation, NSError* error)) failure + success: (void (^)(NSURLSessionDataTask *task, id responseObject, NSDictionary* places)) success + failure: (void (^)(NSURLSessionDataTask *task, NSError* error)) failure owner: (id) owner { #ifdef DDLogInfo @@ -289,8 +292,8 @@ - (void) reversedGeocodingForLatitude: (double) latitude * @param owner Delegate */ - (void) forwardGeocoding: (NSString*) address - success: (void (^)(AFHTTPRequestOperation* operation, id responseObject, NSDictionary* places)) success - failure: (void (^)(AFHTTPRequestOperation* operation, NSError* error)) failure + success: (void (^)(NSURLSessionDataTask *task, id responseObject, NSDictionary* places)) success + failure: (void (^)(NSURLSessionDataTask *task, NSError* error)) failure owner: (id) owner { #ifdef DDLogInfo @@ -310,8 +313,8 @@ - (void) forwardGeocoding: (NSString*) address */ - (void) forwardGeocoding: (NSString*) address language: (NSString*) language - success: (void (^)(AFHTTPRequestOperation* operation, id responseObject, NSDictionary* places)) success - failure: (void (^)(AFHTTPRequestOperation* operation, NSError* error)) failure + success: (void (^)(NSURLSessionDataTask *task, id responseObject, NSDictionary* places)) success + failure: (void (^)(NSURLSessionDataTask *task, NSError* error)) failure owner: (id) owner { #ifdef DDLogInfo @@ -341,8 +344,8 @@ - (void) forwardGeocoding: (NSString*) address radius: (double) radius limitToBounds: (BOOL) limitToBounds language: (NSString*) language - success: (void (^)(AFHTTPRequestOperation* operation, id responseObject, NSDictionary* places)) success - failure: (void (^)(AFHTTPRequestOperation* operation, NSError* error)) failure + success: (void (^)(NSURLSessionDataTask *task, id responseObject, NSDictionary* places)) success + failure: (void (^)(NSURLSessionDataTask *task, NSError* error)) failure owner: (id) owner { #ifdef DDLogInfo @@ -365,4 +368,4 @@ - (void) forwardGeocoding: (NSString*) address [self makeRequestWithParams: params success: success failure: failure owner: owner]; } -@end \ No newline at end of file +@end diff --git a/Classes/ios/YandexGeocoderClient.h b/Classes/ios/YandexGeocoderClient.h index f4fde44..bb843aa 100644 --- a/Classes/ios/YandexGeocoderClient.h +++ b/Classes/ios/YandexGeocoderClient.h @@ -3,16 +3,24 @@ #import "YandexGeocoder.h" +NS_ASSUME_NONNULL_BEGIN + @interface YandexGeocoderClient : NSObject { - AFHTTPRequestOperationManager *_operationManager; + AFHTTPSessionManager *_sessionManager; NSString *_baseUrl; } - (id)initWithBaseURL:(NSString *)url; -- (void)getPath:(NSString *)path delegate:(id)delegate parameters:(NSDictionary *)parameters success:(void (^)(AFHTTPRequestOperation *, id))success failure:(void (^)(AFHTTPRequestOperation *, NSError *))failure; +- (void)getPath:(NSString *)path + delegate:(id)delegate + parameters:(NSDictionary *)parameters + success:(void (^)(NSURLSessionDataTask *task, id responseObject))success + failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure; - (void)cancelAllOperationsForDelegate:(id)delegate; -@end \ No newline at end of file +@end + +NS_ASSUME_NONNULL_END diff --git a/Classes/ios/YandexGeocoderClient.m b/Classes/ios/YandexGeocoderClient.m index ed03b38..b66c808 100644 --- a/Classes/ios/YandexGeocoderClient.m +++ b/Classes/ios/YandexGeocoderClient.m @@ -18,9 +18,9 @@ - (id)initWithBaseURL:(NSString *)url { self = [super init]; if (self) { - _operationManager = [AFHTTPRequestOperationManager manager]; - _operationManager.requestSerializer = [AFHTTPRequestSerializer serializer]; - [_operationManager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"]; + _sessionManager = [AFHTTPSessionManager manager]; + _sessionManager.requestSerializer = [AFHTTPRequestSerializer serializer]; + [_sessionManager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"]; _baseUrl = url; } @@ -35,15 +35,20 @@ - (id)initWithBaseURL:(NSString *)url * @param success Completion block * @param failure Failure block */ -- (void)getPath:(NSString *)path delegate:(id)delegate parameters:(NSDictionary *)parameters success:(void (^)(AFHTTPRequestOperation *operation, id responseObject))success failure:(void (^)(AFHTTPRequestOperation *operation, NSError *error))failure +- (void)getPath:(NSString *)path + delegate:(id)delegate + parameters:(NSDictionary *)parameters + success:(void (^)(NSURLSessionDataTask *task, id responseObject))success + failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure { - AFHTTPRequestOperation *operation = [_operationManager GET:[_baseUrl stringByAppendingString:path] - parameters:parameters - success:success - failure:failure]; + NSURLSessionDataTask *dataTask = [_sessionManager GET:[_baseUrl stringByAppendingString:path] + parameters:parameters + progress:nil + success:success + failure:failure]; - objc_setAssociatedObject(operation, &kGeocodingOperationDelegateObjectKey, delegate, OBJC_ASSOCIATION_ASSIGN); + objc_setAssociatedObject(dataTask, &kGeocodingOperationDelegateObjectKey, delegate, OBJC_ASSOCIATION_ASSIGN); } /** Cancels all operations associated with delegate @@ -52,17 +57,13 @@ - (void)getPath:(NSString *)path delegate:(id)delegate parameters:(NSDictionary */ - (void)cancelAllOperationsForDelegate:(id)delegate { - for (NSOperation *operation in [_operationManager.operationQueue operations]) { - if (![operation isKindOfClass:[AFHTTPRequestOperation class]]) { - continue; - } - - BOOL match = (id)objc_getAssociatedObject(operation, &kGeocodingOperationDelegateObjectKey) == delegate; - + for (NSURLSessionDataTask *task in _sessionManager.dataTasks) { + BOOL match = (id)objc_getAssociatedObject(task, &kGeocodingOperationDelegateObjectKey) == delegate; + if (match) { - [operation cancel]; + [task cancel]; } } } -@end \ No newline at end of file +@end From 122b8cd114e69d0c1f2f41f274c0c8e2528bef7e Mon Sep 17 00:00:00 2001 From: Denis Syrokvash Date: Thu, 19 Jul 2018 17:03:59 +0300 Subject: [PATCH 11/16] switched to https version of the API --- Classes/ios/YandexGeocoder.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Classes/ios/YandexGeocoder.h b/Classes/ios/YandexGeocoder.h index a58fad4..6fada80 100644 --- a/Classes/ios/YandexGeocoder.h +++ b/Classes/ios/YandexGeocoder.h @@ -2,7 +2,7 @@ #import #import "AFNetworking.h" -#define kYandexGeocoderBaseUrl @"http://geocode-maps.yandex.ru/" +#define kYandexGeocoderBaseUrl @"https://geocode-maps.yandex.ru/" #define kYandexGeocoderEarthRadius 6371000.01 @class YandexGeocoderClient; From e5720ebf14b00bb7799c169d3761235ef2c4b0ba Mon Sep 17 00:00:00 2001 From: Denis Syrokvash Date: Thu, 19 Jul 2018 17:04:31 +0300 Subject: [PATCH 12/16] added location usage reason, required for CLLocationManager --- .../YandexGeocoderExample/YandexGeocoderExample-Info.plist | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Project/YandexGeocoderExample/YandexGeocoderExample/YandexGeocoderExample-Info.plist b/Project/YandexGeocoderExample/YandexGeocoderExample/YandexGeocoderExample-Info.plist index 8a34c1e..fec3463 100644 --- a/Project/YandexGeocoderExample/YandexGeocoderExample/YandexGeocoderExample-Info.plist +++ b/Project/YandexGeocoderExample/YandexGeocoderExample/YandexGeocoderExample-Info.plist @@ -26,6 +26,8 @@ UIMainStoryboardFile MainStoryboard + NSLocationWhenInUseUsageDescription + Requires location for testing geocoder UIRequiredDeviceCapabilities armv7 From f4dd2ac6353739c270aa9d518e122f8603c81f67 Mon Sep 17 00:00:00 2001 From: Denis Syrokvash Date: Thu, 19 Jul 2018 17:05:07 +0300 Subject: [PATCH 13/16] updated to modern usage of CLLocationManager updated to new callbacks from YandexGeocoder pod --- .../YandexGeocoderExample/YGViewController.m | 38 ++++++++++++++----- 1 file changed, 28 insertions(+), 10 deletions(-) diff --git a/Project/YandexGeocoderExample/YandexGeocoderExample/YGViewController.m b/Project/YandexGeocoderExample/YandexGeocoderExample/YGViewController.m index e1c8fb5..bd78726 100644 --- a/Project/YandexGeocoderExample/YandexGeocoderExample/YGViewController.m +++ b/Project/YandexGeocoderExample/YandexGeocoderExample/YGViewController.m @@ -32,6 +32,12 @@ - (void)viewDidLoad self.manager.headingFilter = 30.0; } +- (void)viewDidAppear:(BOOL)animated { + [super viewDidAppear:animated]; + + [self.manager requestWhenInUseAuthorization]; +} + - (void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; @@ -60,20 +66,32 @@ - (void)yandexGeocoderRequestFailed - (IBAction)onQueryToLocations:(id)sender { [self.query resignFirstResponder]; - [[YandexGeocoder sharedInstance] forwardGeocoding:self.query.text language:@"RU" success:^(AFHTTPRequestOperation *operation, id responseObject, NSDictionary *places) { - [self yandexGeocoderRequestFinished:places]; - } failure:^(AFHTTPRequestOperation *operation, NSError *error) { - [self yandexGeocoderRequestFailed]; - } owner:self]; + [[YandexGeocoder sharedInstance] forwardGeocoding:self.query.text + language:@"RU" + success:^(NSURLSessionDataTask *task, id responseObject, NSDictionary *places) { + + [self yandexGeocoderRequestFinished:places]; + + } failure:^(NSURLSessionDataTask *task, NSError *error) { + + [self yandexGeocoderRequestFailed]; + + } owner:self]; } - (void)locationManager:(CLLocationManager *)manager didUpdateLocations:(NSArray *)locations { CLLocation *location = locations[0]; - [[YandexGeocoder sharedInstance] reversedGeocodingForLatitude:location.coordinate.latitude longitude:location.coordinate.longitude language:@"EN" kind:@"house" success:^(AFHTTPRequestOperation *operation, id responseObject, NSDictionary *places) { - [self yandexGeocoderRequestFinished:places]; - } failure:^(AFHTTPRequestOperation *operation, NSError *error) { - [self yandexGeocoderRequestFailed]; - } owner:self]; + [[YandexGeocoder sharedInstance] reversedGeocodingForLatitude:location.coordinate.latitude + longitude:location.coordinate.longitude + language:@"EN" + kind:@"house" + success:^(NSURLSessionDataTask *task, id responseObject, NSDictionary *places) { + [self yandexGeocoderRequestFinished:places]; + } + failure:^(NSURLSessionDataTask *task, NSError *error) { + [self yandexGeocoderRequestFailed]; + } + owner:self]; } @end From 137804c34f3d497c3e143cee65173b8afe2816d7 Mon Sep 17 00:00:00 2001 From: Denis Syrokvash Date: Thu, 19 Jul 2018 17:06:43 +0300 Subject: [PATCH 14/16] bumped podspec version to 0.2.0 --- YandexGeocoder.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/YandexGeocoder.podspec b/YandexGeocoder.podspec index 04ae18e..fd62c2c 100644 --- a/YandexGeocoder.podspec +++ b/YandexGeocoder.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "YandexGeocoder" - s.version = "0.1.0" + s.version = "0.2.0" s.summary = "Use Yandex Geocoding API for forward and reversed geocoding." s.homepage = "https://github.com/exister/YandexGeocoder" s.license = 'MIT' From e96b79612e7d2ef731b801c97b011c8652508031 Mon Sep 17 00:00:00 2001 From: Denis Syrokvash Date: Wed, 25 Jul 2018 17:08:03 +0300 Subject: [PATCH 15/16] added additional method for correct usage of span parameter --- Classes/ios/YandexGeocoder.h | 10 +++++++++ Classes/ios/YandexGeocoder.m | 41 ++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+) diff --git a/Classes/ios/YandexGeocoder.h b/Classes/ios/YandexGeocoder.h index 6fada80..b3e8c21 100644 --- a/Classes/ios/YandexGeocoder.h +++ b/Classes/ios/YandexGeocoder.h @@ -55,6 +55,16 @@ success:(void (^)(NSURLSessionDataTask *task, id responseObject, NSDictionary *places))success failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure owner:(id)owner; +- (void)forwardGeocoding:(NSString *)address + limitCenterLat:(double)limitCenterLat + limitCenterLng:(double)limitCenterLng + limitSpanLat:(double)spanLat + limitSpanLng:(double)spanLng + limitToBounds:(BOOL)limitToBounds + language:(NSString *)language + success:(void (^)(NSURLSessionDataTask *task, id responseObject, NSDictionary *places))success + failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure owner:(id)owner; + + (CLLocation *)locationFromObject:(NSDictionary *)object; + (NSString *)titleFromObject:(NSDictionary *)object; diff --git a/Classes/ios/YandexGeocoder.m b/Classes/ios/YandexGeocoder.m index 14e18fb..d834f4e 100644 --- a/Classes/ios/YandexGeocoder.m +++ b/Classes/ios/YandexGeocoder.m @@ -368,4 +368,45 @@ - (void) forwardGeocoding: (NSString*) address [self makeRequestWithParams: params success: success failure: failure owner: owner]; } + +/** Get list of places for address + * + * @param address Query string + * @param limitCenterLat Latitude of the center of the bounding area + * @param limitCenterLng Longitude of the center of the bounding area + * @param spanLat span in degrees for latitude + * @param spanLng span in degrees for longitude + * @param limitToBounds YES - limit search to bounding area, NO - don't limit, but return results within the bounding area first + */ +- (void)forwardGeocoding:(NSString *)address + limitCenterLat:(double)limitCenterLat + limitCenterLng:(double)limitCenterLng + limitSpanLat:(double)spanLat + limitSpanLng:(double)spanLng + limitToBounds:(BOOL)limitToBounds + language:(NSString *)language + success:(void (^)(NSURLSessionDataTask *task, id responseObject, NSDictionary *places))success + failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure owner:(id)owner { + +#ifdef DDLogInfo + DDLogInfo(@"Forward geocoding: %@, lat %f, lng %f, spn-lat %f, spn-lng %f, limit %d", address, limitCenterLat, limitCenterLng, spanLat, spanLng, limitToBounds); +#else + NSLog(@"Forward geocoding: %@, lat %f, lng %f, spn-lat %f, spn-lng %f, limit %d", address, limitCenterLat, limitCenterLng, spanLat, spanLng, limitToBounds); +#endif + NSMutableDictionary* params = [@{ + @"geocode" : address, + @"rspn" : limitToBounds ? @"1" : @"0", + @"ll" : [NSString stringWithFormat: @"%.07f,%.07f", limitCenterLng, limitCenterLat], + @"spn" : [NSString stringWithFormat: @"%.07f,%.07f", spanLng, spanLat] + } mutableCopy]; + + if (language != nil) + { + params[@"lang"] = language; + } + + [self makeRequestWithParams: params success: success failure: failure owner: owner]; + +} + @end From 4c811c0e69bd3198b3e49885efca52e88af57f8e Mon Sep 17 00:00:00 2001 From: Denis Syrokvash Date: Wed, 25 Jul 2018 17:08:48 +0300 Subject: [PATCH 16/16] updated podspec with bumped version 0.2.1 --- YandexGeocoder.podspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/YandexGeocoder.podspec b/YandexGeocoder.podspec index fd62c2c..45c5112 100644 --- a/YandexGeocoder.podspec +++ b/YandexGeocoder.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "YandexGeocoder" - s.version = "0.2.0" + s.version = "0.2.1" s.summary = "Use Yandex Geocoding API for forward and reversed geocoding." s.homepage = "https://github.com/exister/YandexGeocoder" s.license = 'MIT'