Guest User

Untitled

a guest
Jan 18th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.23 KB | None | 0 0
  1. [NSThread detachNewThreadSelector:@selector(loadPList) toTarget:self withObject:nil];
  2.  
  3. - (void) loadPList
  4. {
  5.  
  6. NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  7. NSString *path = [[documentPaths lastObject] stringByAppendingPathComponent:@"test.plist"];
  8.  
  9. NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path]; // memory leak here
  10.  
  11. NSMutableArray *annotations = [[NSMutableArray alloc]init];
  12.  
  13.  
  14. dispatch_async(dispatch_get_main_queue(), ^{
  15.  
  16.  
  17. NSMutableArray * annotationsToRemove = [ mapView.annotations mutableCopy ] ;
  18. [ annotationsToRemove removeObject:mapView.userLocation ] ;
  19. [ mapView removeAnnotations:annotationsToRemove ] ;
  20.  
  21.  
  22.  
  23. if ([[NSUserDefaults standardUserDefaults] boolForKey:@"blackKey"])
  24. {
  25.  
  26. NSArray *ann = [dict objectForKey:@"Black"];
  27.  
  28. for(int i = 0; i < [ann count]; i++) {
  29.  
  30. NSString *coordinates = [[ann objectAtIndex:i] objectForKey:@"Coordinates"];
  31.  
  32. double realLatitude = [[[coordinates componentsSeparatedByString:@","] objectAtIndex:1] doubleValue];
  33. double realLongitude = [[[coordinates componentsSeparatedByString:@","] objectAtIndex:0] doubleValue];
  34.  
  35. MyAnnotation *myAnnotation = [[MyAnnotation alloc] init];
  36. CLLocationCoordinate2D theCoordinate;
  37. theCoordinate.latitude = realLatitude;
  38. theCoordinate.longitude = realLongitude;
  39.  
  40. myAnnotation.coordinate=CLLocationCoordinate2DMake(realLatitude,realLongitude);
  41. myAnnotation.title = [[ann objectAtIndex:i] objectForKey:@"Name"];
  42. myAnnotation.subtitle = [[ann objectAtIndex:i] objectForKey:@"Address"];
  43. myAnnotation.icon = [[ann objectAtIndex:0] objectForKey:@"Icon"];
  44.  
  45. [mapView addAnnotation:myAnnotation];
  46. [annotations addObject:myAnnotation];
  47.  
  48. }
  49.  
  50. }
  51.  
  52.  
  53. });
  54.  
  55.  
  56. }
  57.  
  58. dispatch_async(get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  59. [self loadPlist];
  60. });
  61.  
  62. NSMutableArray *annotations = [[NSMutableArray alloc]init]; // Never released
  63. NSMutableArray * annotationsToRemove = [ mapView.annotations mutableCopy ] ; // Never released
  64. MyAnnotation *myAnnotation = [[MyAnnotation alloc] init]; // Never released
  65.  
  66. - (void) loadPList {
  67. NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
  68. NSString *path = [[documentPaths lastObject] stringByAppendingPathComponent:@"test.plist"];
  69. NSDictionary *dict = [NSDictionary dictionaryWithContentsOfFile:path]; // memory leak here
  70. NSMutableArray *annotations = [[[NSMutableArray alloc] init] autorelease];
  71. dispatch_async(dispatch_get_main_queue(), ^{
  72. NSMutableArray * annotationsToRemove = [[mapView.annotations mutableCopy] autorelease];
  73. [annotationsToRemove removeObject:mapView.userLocation] ;
  74. [mapView removeAnnotations:annotationsToRemove] ;
  75. if ([[NSUserDefaults standardUserDefaults] boolForKey:@"blackKey"])
  76. {
  77.  
  78. NSArray *ann = [dict objectForKey:@"Black"];
  79.  
  80. for(int i = 0; i < [ann count]; i++) {
  81.  
  82. NSString *coordinates = [[ann objectAtIndex:i] objectForKey:@"Coordinates"];
  83.  
  84. double realLatitude = [[[coordinates componentsSeparatedByString:@","] objectAtIndex:1] doubleValue];
  85. double realLongitude = [[[coordinates componentsSeparatedByString:@","] objectAtIndex:0] doubleValue];
  86.  
  87. MyAnnotation *myAnnotation = [[[MyAnnotation alloc] init] autorelease];
  88. CLLocationCoordinate2D theCoordinate;
  89. theCoordinate.latitude = realLatitude;
  90. theCoordinate.longitude = realLongitude;
  91.  
  92. myAnnotation.coordinate=CLLocationCoordinate2DMake(realLatitude,realLongitude);
  93. myAnnotation.title = [[ann objectAtIndex:i] objectForKey:@"Name"];
  94. myAnnotation.subtitle = [[ann objectAtIndex:i] objectForKey:@"Address"];
  95. myAnnotation.icon = [[ann objectAtIndex:0] objectForKey:@"Icon"];
  96.  
  97. [mapView addAnnotation:myAnnotation];
  98. [annotations addObject:myAnnotation];
  99.  
  100. }
  101. }
  102. });
  103. }
Add Comment
Please, Sign In to add comment