Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- [NSThread detachNewThreadSelector:@selector(loadPList) toTarget:self withObject:nil];
- - (void) loadPList
- {
- NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *path = [[documentPaths lastObject] stringByAppendingPathComponent:@"test.plist"];
- NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path]; // memory leak here
- NSMutableArray *annotations = [[NSMutableArray alloc]init];
- dispatch_async(dispatch_get_main_queue(), ^{
- NSMutableArray * annotationsToRemove = [ mapView.annotations mutableCopy ] ;
- [ annotationsToRemove removeObject:mapView.userLocation ] ;
- [ mapView removeAnnotations:annotationsToRemove ] ;
- if ([[NSUserDefaults standardUserDefaults] boolForKey:@"blackKey"])
- {
- NSArray *ann = [dict objectForKey:@"Black"];
- for(int i = 0; i < [ann count]; i++) {
- NSString *coordinates = [[ann objectAtIndex:i] objectForKey:@"Coordinates"];
- double realLatitude = [[[coordinates componentsSeparatedByString:@","] objectAtIndex:1] doubleValue];
- double realLongitude = [[[coordinates componentsSeparatedByString:@","] objectAtIndex:0] doubleValue];
- MyAnnotation *myAnnotation = [[MyAnnotation alloc] init];
- CLLocationCoordinate2D theCoordinate;
- theCoordinate.latitude = realLatitude;
- theCoordinate.longitude = realLongitude;
- myAnnotation.coordinate=CLLocationCoordinate2DMake(realLatitude,realLongitude);
- myAnnotation.title = [[ann objectAtIndex:i] objectForKey:@"Name"];
- myAnnotation.subtitle = [[ann objectAtIndex:i] objectForKey:@"Address"];
- myAnnotation.icon = [[ann objectAtIndex:0] objectForKey:@"Icon"];
- [mapView addAnnotation:myAnnotation];
- [annotations addObject:myAnnotation];
- }
- }
- });
- }
- dispatch_async(get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- [self loadPlist];
- });
- NSMutableArray *annotations = [[NSMutableArray alloc]init]; // Never released
- NSMutableArray * annotationsToRemove = [ mapView.annotations mutableCopy ] ; // Never released
- MyAnnotation *myAnnotation = [[MyAnnotation alloc] init]; // Never released
- - (void) loadPList {
- NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
- NSString *path = [[documentPaths lastObject] stringByAppendingPathComponent:@"test.plist"];
- NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path]; // memory leak here
- NSMutableArray *annotations = [[[NSMutableArray alloc] init] autorelease];
- dispatch_async(dispatch_get_main_queue(), ^{
- NSMutableArray * annotationsToRemove = [[mapView.annotations mutableCopy] autorelease];
- [annotationsToRemove removeObject:mapView.userLocation] ;
- [mapView removeAnnotations:annotationsToRemove] ;
- if ([[NSUserDefaults standardUserDefaults] boolForKey:@"blackKey"])
- {
- NSArray *ann = [dict objectForKey:@"Black"];
- for(int i = 0; i < [ann count]; i++) {
- NSString *coordinates = [[ann objectAtIndex:i] objectForKey:@"Coordinates"];
- double realLatitude = [[[coordinates componentsSeparatedByString:@","] objectAtIndex:1] doubleValue];
- double realLongitude = [[[coordinates componentsSeparatedByString:@","] objectAtIndex:0] doubleValue];
- MyAnnotation *myAnnotation = [[[MyAnnotation alloc] init] autorelease];
- CLLocationCoordinate2D theCoordinate;
- theCoordinate.latitude = realLatitude;
- theCoordinate.longitude = realLongitude;
- myAnnotation.coordinate=CLLocationCoordinate2DMake(realLatitude,realLongitude);
- myAnnotation.title = [[ann objectAtIndex:i] objectForKey:@"Name"];
- myAnnotation.subtitle = [[ann objectAtIndex:i] objectForKey:@"Address"];
- myAnnotation.icon = [[ann objectAtIndex:0] objectForKey:@"Icon"];
- [mapView addAnnotation:myAnnotation];
- [annotations addObject:myAnnotation];
- }
- }
- });
- }
Add Comment
Please, Sign In to add comment