diff --git a/Classes/ios/YandexGeocoder.h b/Classes/ios/YandexGeocoder.h index 4430d06..b3e8c21 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; @@ -14,15 +14,56 @@ - (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)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)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 (^)(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 (^)(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; @@ -32,4 +73,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 9f10ef1..d834f4e 100644 --- a/Classes/ios/YandexGeocoder.m +++ b/Classes/ios/YandexGeocoder.m @@ -7,13 +7,16 @@ @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; +- (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 +24,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: kYandexGeocoderBaseUrl]; } return self; } @@ -53,46 +60,56 @@ - (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 - 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 { 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: ^(NSURLSessionDataTask *task, 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(task, responseObject, places); + } + else + { + failure(task, [NSError errorWithDomain: @"com.yandex.geocode" code: 404 + userInfo: @{@"error" : @"Can't find places"}]); + } + } failure: ^(NSURLSessionDataTask *task, NSError* error) { #ifdef DDLogError DDLogError(@"Yandex Geocoder failed"); #else NSLog(@"Yandex Geocoder failed"); #endif - failure(operation, error); + failure(task, error); }]; } /** 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 +117,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 +149,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 +159,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 +172,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 +182,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 +208,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"]; } @@ -197,15 +220,16 @@ + (NSString *)placeTypeFromObject:(NSDictionary *)object * * @param latitude Latitude * @param longitude Longitude -* @param delegate Delegate +* @param owner 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 (^)(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 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 @@ -213,15 +237,17 @@ - (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 - 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 (^)(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 + failure: failure owner: owner]; } /** Get list of places at point @@ -230,50 +256,78 @@ - (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 - 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 (^)(NSURLSessionDataTask *task, id responseObject, NSDictionary* places)) success + failure: (void (^)(NSURLSessionDataTask *task, 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 * * @param address Query string -* @param address delegate Delegate +* @param owner 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 (^)(NSURLSessionDataTask *task, id responseObject, NSDictionary* places)) success + failure: (void (^)(NSURLSessionDataTask *task, 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 + * + * @param address Query string + * @param language Language Code + * @param owner Delegate + */ +- (void) forwardGeocoding: (NSString*) address + 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: %@", 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 @@ -284,33 +338,75 @@ - (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 (^)(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, 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 + +/** 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 diff --git a/Classes/ios/YandexGeocoderClient.h b/Classes/ios/YandexGeocoderClient.h index 1b35896..bb843aa 100644 --- a/Classes/ios/YandexGeocoderClient.h +++ b/Classes/ios/YandexGeocoderClient.h @@ -2,12 +2,25 @@ #import "AFNetworking.h" #import "YandexGeocoder.h" -@class AFHTTPRequestOperation; +NS_ASSUME_NONNULL_BEGIN -@interface YandexGeocoderClient : AFHTTPClient -- (void)getPath:(NSString *)path delegate:(id)delegate parameters:(NSDictionary *)parameters success:(void (^)(AFHTTPRequestOperation *, id))success failure:(void (^)(AFHTTPRequestOperation *, NSError *))failure; +@interface YandexGeocoderClient : NSObject +{ + AFHTTPSessionManager *_sessionManager; + NSString *_baseUrl; +} + +- (id)initWithBaseURL:(NSString *)url; + +- (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 c962bcf..b66c808 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"]; + _sessionManager = [AFHTTPSessionManager manager]; + _sessionManager.requestSerializer = [AFHTTPRequestSerializer serializer]; + [_sessionManager.requestSerializer setValue:@"application/json" forHTTPHeaderField:@"Accept"]; + _baseUrl = url; } return self; @@ -36,17 +35,20 @@ - (id)initWithBaseURL:(NSURL *)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 { - NSURLRequest *request = [self requestWithMethod:@"GET" path:path parameters:parameters]; - - NSLog(@"%@", request.URL); - - AFHTTPRequestOperation *operation = [self HTTPRequestOperationWithRequest:request success:success failure:failure]; - - objc_setAssociatedObject(operation, &kGeocodingOperationDelegateObjectKey, delegate, OBJC_ASSOCIATION_ASSIGN); - - [self enqueueHTTPRequestOperation:operation]; + + NSURLSessionDataTask *dataTask = [_sessionManager GET:[_baseUrl stringByAppendingString:path] + parameters:parameters + progress:nil + success:success + failure:failure]; + + objc_setAssociatedObject(dataTask, &kGeocodingOperationDelegateObjectKey, delegate, OBJC_ASSOCIATION_ASSIGN); } /** Cancels all operations associated with delegate @@ -55,17 +57,13 @@ - (void)getPath:(NSString *)path delegate:(id)delegate parameters:(NSDictionary */ - (void)cancelAllOperationsForDelegate:(id)delegate { - for (NSOperation *operation in [self.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 diff --git a/Project/YandexGeocoderExample/Podfile b/Project/YandexGeocoderExample/Podfile index a8316ab..49ac827 100644 --- a/Project/YandexGeocoderExample/Podfile +++ b/Project/YandexGeocoderExample/Podfile @@ -1,3 +1,5 @@ -platform :ios, '5.0' +platform :ios, '8.0' -pod 'YandexGeocoder', :local => "../../../YandexGeocoder" \ No newline at end of file +target 'YandexGeocoderExample' do + pod 'YandexGeocoder', :path => "../../../YandexGeocoder" +end diff --git a/Project/YandexGeocoderExample/YandexGeocoderExample.xcodeproj/project.pbxproj b/Project/YandexGeocoderExample/YandexGeocoderExample.xcodeproj/project.pbxproj index d227892..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 */; settings = {}; }; 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 = ""; }; - ACB122C2242945E5BB2AD89C /* libPods.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; name = libPods.a; 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; }; + 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; }; /* 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" */; @@ -226,8 +238,6 @@ mainGroup = 18A039C6168F3DD700550B8D; productRefGroup = 18A039D2168F3DD700550B8D /* Products */; projectDirPath = ""; - projectReferences = ( - ); projectRoot = ""; targets = ( 18A039D0168F3DD700550B8D /* YandexGeocoderExample */, @@ -273,20 +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"; - showEnvVarsInLog = 1; + 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 */ @@ -354,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; }; @@ -382,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; @@ -399,11 +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 = 8.0; + PRODUCT_BUNDLE_IDENTIFIER = "com.mkuznetsov.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -411,11 +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 = 8.0; + PRODUCT_BUNDLE_IDENTIFIER = "com.mkuznetsov.${PRODUCT_NAME:rfc1034identifier}"; PRODUCT_NAME = "$(TARGET_NAME)"; WRAPPER_EXTENSION = app; }; @@ -432,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; @@ -449,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; @@ -474,6 +534,7 @@ 18A03A0C168F3DD800550B8D /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; 18A03A0D168F3DD800550B8D /* Build configuration list for PBXNativeTarget "YandexGeocoderExampleTests" */ = { isa = XCConfigurationList; @@ -482,6 +543,7 @@ 18A03A0F168F3DD800550B8D /* Release */, ); defaultConfigurationIsVisible = 0; + defaultConfigurationName = Release; }; /* End XCConfigurationList section */ }; 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 @@ + + + + + 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/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..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]; @@ -44,19 +50,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 +64,34 @@ - (void)yandexGeocoderRequestFailed self.console.text = @"Geocoding failed"; } +- (IBAction)onQueryToLocations:(id)sender { + [self.query resignFirstResponder]; + [[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 delegate: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 diff --git a/Project/YandexGeocoderExample/YandexGeocoderExample/YandexGeocoderExample-Info.plist b/Project/YandexGeocoderExample/YandexGeocoderExample/YandexGeocoderExample-Info.plist index f5e0890..fec3463 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 @@ -26,6 +26,8 @@ UIMainStoryboardFile MainStoryboard + NSLocationWhenInUseUsageDescription + Requires location for testing geocoder UIRequiredDeviceCapabilities armv7 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 diff --git a/YandexGeocoder.podspec b/YandexGeocoder.podspec index f30d95b..45c5112 100644 --- a/YandexGeocoder.podspec +++ b/YandexGeocoder.podspec @@ -1,14 +1,14 @@ Pod::Spec.new do |s| s.name = "YandexGeocoder" - s.version = "0.0.5" + 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' 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.source = { :git => "https://github.com/exister/YandexGeocoder.git" } + s.platform = :ios, '8.0' s.source_files = 'Classes/**/*.{h,m}' s.requires_arc = true s.weak_frameworks = 'CoreLocation' - s.dependency 'AFNetworking', '~> 1.3.0' + s.dependency 'AFNetworking', '~> 3.2' end