9
9
#import " ccMacros.h"
10
10
#import " CCPackageHelper.h"
11
11
#import " CCPackage_private.h"
12
+ #import " CCDirector.h"
12
13
13
14
14
15
@interface CCPackageManager ()
@@ -338,7 +339,7 @@ - (void)downloadProgressOfPackage:(CCPackage *)package downloadedBytes:(NSUInteg
338
339
339
340
- (void )unzipFinished : (CCPackageUnzipper *)packageUnzipper
340
341
{
341
- [self runOnMainQueue : ^
342
+ [self runOnCocosThread : ^
342
343
{
343
344
[self removeDownloadFile: packageUnzipper.package];
344
345
@@ -362,7 +363,7 @@ - (void)unzipFinished:(CCPackageUnzipper *)packageUnzipper
362
363
363
364
- (void )unzipFailed : (CCPackageUnzipper *)packageUnzipper error : (NSError *)error
364
365
{
365
- [self runOnMainQueue : ^
366
+ [self runOnCocosThread : ^
366
367
{
367
368
[_unzipTasks removeObject: packageUnzipper];
368
369
@@ -372,7 +373,7 @@ - (void)unzipFailed:(CCPackageUnzipper *)packageUnzipper error:(NSError *)error
372
373
373
374
- (void )unzipProgress : (CCPackageUnzipper *)packageUnzipper unzippedBytes : (NSUInteger )unzippedBytes totalBytes : (NSUInteger )totalBytes
374
375
{
375
- [self runOnMainQueue : ^
376
+ [self runOnCocosThread : ^
376
377
{
377
378
if ([_delegate respondsToSelector: @selector (packageUnzippingProgress:unzippedBytes:totalBytes: )])
378
379
{
@@ -752,15 +753,15 @@ - (void)request:(NSMutableURLRequest *)request ofPackage:(CCPackage *)package
752
753
}
753
754
}
754
755
755
- - (void )runOnMainQueue : (dispatch_block_t )block
756
+ - (void )runOnCocosThread : (dispatch_block_t )block
756
757
{
757
- if ([NSThread isMainThread ])
758
+ if ([[ NSThread currentThread ] isEqual: [[CCDirector sharedDirector ] runningThread ] ])
758
759
{
759
760
block ();
760
761
}
761
762
else
762
763
{
763
- dispatch_sync ( dispatch_get_main_queue (), block) ;
764
+ [ self performSelector: _cmd onThread: [[CCDirector sharedDirector ] runningThread ] withObject: block waitUntilDone: YES ] ;
764
765
}
765
766
}
766
767
0 commit comments