|
@@ -331,7 +331,10 @@ |
|
@@ -331,7 +331,10 @@ |
331
|
forTileSource:_activeTileSource
|
331
|
forTileSource:_activeTileSource
|
332
|
usingCache:self];
|
332
|
usingCache:self];
|
333
|
|
333
|
|
334
|
- __block RMTileCacheDownloadOperation *internalOperation = operation;
|
334
|
+ __weak __block RMTileCacheDownloadOperation *internalOperation = operation;
|
|
|
335
|
+ __weak __block NSOperationQueue *weakBackgroundFetchQueue = _backgroundFetchQueue;
|
|
|
336
|
+ __weak __block id<RMTileSource> weakActiveTileSource = _activeTileSource;
|
|
|
337
|
+ __weak RMTileCache *weakSelf = self;
|
335
|
|
338
|
|
336
|
[operation setCompletionBlock:^(void)
|
339
|
[operation setCompletionBlock:^(void)
|
337
|
{
|
340
|
{
|
|
@@ -342,16 +345,18 @@ |
|
@@ -342,16 +345,18 @@ |
342
|
progTile++;
|
345
|
progTile++;
|
343
|
|
346
|
|
344
|
if ([_backgroundCacheDelegate respondsToSelector:@selector(tileCache:didBackgroundCacheTile:withIndex:ofTotalTileCount:)])
|
347
|
if ([_backgroundCacheDelegate respondsToSelector:@selector(tileCache:didBackgroundCacheTile:withIndex:ofTotalTileCount:)])
|
345
|
- [_backgroundCacheDelegate tileCache:self didBackgroundCacheTile:RMTileMake(x, y, zoom) withIndex:progTile ofTotalTileCount:totalTiles];
|
348
|
+ [_backgroundCacheDelegate tileCache:weakSelf
|
|
|
349
|
+ didBackgroundCacheTile:RMTileMake(x, y, zoom)
|
|
|
350
|
+ withIndex:progTile
|
|
|
351
|
+ ofTotalTileCount:totalTiles];
|
346
|
|
352
|
|
347
|
if (progTile == totalTiles)
|
353
|
if (progTile == totalTiles)
|
348
|
{
|
354
|
{
|
349
|
- _backgroundFetchQueue = nil;
|
|
|
350
|
-
|
|
|
351
|
- _activeTileSource = nil;
|
355
|
+ weakBackgroundFetchQueue = nil;
|
|
|
356
|
+ weakActiveTileSource = nil;
|
352
|
|
357
|
|
353
|
if ([_backgroundCacheDelegate respondsToSelector:@selector(tileCacheDidFinishBackgroundCache:)])
|
358
|
if ([_backgroundCacheDelegate respondsToSelector:@selector(tileCacheDidFinishBackgroundCache:)])
|
354
|
- [_backgroundCacheDelegate tileCacheDidFinishBackgroundCache:self];
|
359
|
+ [_backgroundCacheDelegate tileCacheDidFinishBackgroundCache:weakSelf];
|
355
|
}
|
360
|
}
|
356
|
}
|
361
|
}
|
357
|
|
362
|
|
|
@@ -362,35 +367,39 @@ |
|
@@ -362,35 +367,39 @@ |
362
|
[_backgroundFetchQueue addOperation:operation];
|
367
|
[_backgroundFetchQueue addOperation:operation];
|
363
|
}
|
368
|
}
|
364
|
}
|
369
|
}
|
365
|
- };
|
370
|
+ }
|
366
|
}
|
371
|
}
|
367
|
|
372
|
|
368
|
- (void)cancelBackgroundCache
|
373
|
- (void)cancelBackgroundCache
|
369
|
{
|
374
|
{
|
|
|
375
|
+ __weak RMTileCache *weakSelf = self;
|
|
|
376
|
+ __weak __block NSOperationQueue *weakBackgroundFetchQueue = _backgroundFetchQueue;
|
|
|
377
|
+ __weak __block id<RMTileSource> weakActiveTileSource = _activeTileSource;
|
|
|
378
|
+
|
370
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void)
|
379
|
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(void)
|
371
|
{
|
380
|
{
|
372
|
- @synchronized (self)
|
381
|
+ @synchronized (weakSelf)
|
373
|
{
|
382
|
{
|
374
|
BOOL didCancel = NO;
|
383
|
BOOL didCancel = NO;
|
375
|
|
384
|
|
376
|
- if (_backgroundFetchQueue)
|
385
|
+ if (weakBackgroundFetchQueue)
|
377
|
{
|
386
|
{
|
378
|
- [_backgroundFetchQueue cancelAllOperations];
|
|
|
379
|
- [_backgroundFetchQueue waitUntilAllOperationsAreFinished];
|
|
|
380
|
- _backgroundFetchQueue = nil;
|
387
|
+ [weakBackgroundFetchQueue cancelAllOperations];
|
|
|
388
|
+ [weakBackgroundFetchQueue waitUntilAllOperationsAreFinished];
|
|
|
389
|
+ weakBackgroundFetchQueue = nil;
|
381
|
|
390
|
|
382
|
didCancel = YES;
|
391
|
didCancel = YES;
|
383
|
}
|
392
|
}
|
384
|
|
393
|
|
385
|
- if (_activeTileSource)
|
|
|
386
|
- _activeTileSource = nil;
|
394
|
+ if (weakActiveTileSource)
|
|
|
395
|
+ weakActiveTileSource = nil;
|
387
|
|
396
|
|
388
|
if (didCancel)
|
397
|
if (didCancel)
|
389
|
{
|
398
|
{
|
390
|
dispatch_sync(dispatch_get_main_queue(), ^(void)
|
399
|
dispatch_sync(dispatch_get_main_queue(), ^(void)
|
391
|
{
|
400
|
{
|
392
|
if ([_backgroundCacheDelegate respondsToSelector:@selector(tileCacheDidCancelBackgroundCache:)])
|
401
|
if ([_backgroundCacheDelegate respondsToSelector:@selector(tileCacheDidCancelBackgroundCache:)])
|
393
|
- [_backgroundCacheDelegate tileCacheDidCancelBackgroundCache:self];
|
402
|
+ [_backgroundCacheDelegate tileCacheDidCancelBackgroundCache:weakSelf];
|
394
|
});
|
403
|
});
|
395
|
}
|
404
|
}
|
396
|
}
|
405
|
}
|