Почему этот блок кода не выполняется? Я скопировал и вставил его из другого моего проекта, где он работает просто отлично. Я также попробовал это в моем другом приложении с тем же addressString
, который я подключил здесь, и он работал отлично.
NSString *addressString = [NSString stringWithFormat:@"%@ and %@, %@, NY", street, rightBound, [boroughs objectForKey:borough]];
NSLog(@"Address string: %@",addressString);
[geocoder geocodeAddressString:addressString completionHandler:^(NSArray *placemarks, NSError *error)
{
NSLog(@"Placemark count:%d",[placemarks count]);
for(CLPlacemark *placemark in placemarks)
{
NSLog(@"%@",placemark);
}
if(anError)
{
NSLog(@"Error: %@",[error description]);
}
}];
Ни метки, ни сообщения об ошибках не регистрируются в консоли.
Вот мой весь AppDelegate.m:
@implementation AppDelegate
@synthesize window = _window;
- (void)dealloc
{
[_window release];
[super dealloc];
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSError *error = nil;
SBJsonParser *parser = [[SBJsonParser alloc] init];
NSString *JSONString = [NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Streets" ofType:@"json"] encoding:NSUTF8StringEncoding error:&error];
if(error)
{
NSLog(@"%@",[error description]);
NSLog(@"Break");
}
NSDictionary *dict = [parser objectWithString:JSONString error:&error];
if(error)
{
NSLog(@"%@",[error description]);
NSLog(@"Break");
}
NSArray *addresses = [[dict objectForKey:@"results"] retain];
NSDictionary *boroughs = [NSDictionary dictionaryWithObjects:[NSArray arrayWithObjects:@"Bronx",@"Brooklyn",@"New York", @"Queens",@"Staten Island",nil] forKeys:[NSArray arrayWithObjects:@"B",@"K",@"M",@"Q",@"S", nil]];
int i = 1;
for(NSDictionary *file in addresses)
{
NSString *borough = [file objectForKey:@"Borough"];
NSString *ID = [file objectForKey:@"ID"];
NSString *leftBound = [file objectForKey:@"LeftBound"];
NSString *rightBound = [file objectForKey:@"RightBound"];
NSString *sideOfStreet = [file objectForKey:@"SideOfStreet"];
NSString *street = [file objectForKey:@"Street"];
NSString *addressString = [NSString stringWithFormat:@"%@ and %@, %@, NY", street, rightBound, [boroughs objectForKey:borough]];
// NSLog(@"Address string: %@",addressString);
CLGeocoder *geocoder = [[CLGeocoder alloc] init];
[geocoder geocodeAddressString:addressString completionHandler:^(NSArray *placemarks, NSError *anError)
{
NSLog(@"AAAAAAAAAAAAAAAAAAAAAAAA");
NSLog(@"Placemark count:%d",[placemarks count]);
for(CLPlacemark *placemark in placemarks)
{
NSLog(@"Placemark: %@",placemark);
}
if(anError)
{
NSLog(@"Error: %@",[error description]);
}
}];
[geocoder release];
NSLog(@"%d",i++);
}
[parser release];
[addresses release];
self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
// Override point for customization after application launch.
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
-(void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if([keyPath isEqualToString:@"geocoder"])
{
NSLog(@"AAAAAAA");
}
}
@end