Browse Source

Box: Dispatch UI method on the mainthread

Close #664
Soomin Lee 5 years ago
parent
commit
28f40ef2b1
2 changed files with 24 additions and 12 deletions
  1. 22 11
      Sources/VLCBoxController.m
  2. 2 1
      Sources/VLCBoxTableViewController.m

+ 22 - 11
Sources/VLCBoxController.m

@@ -196,9 +196,10 @@
 
 
     [self loadFile:file intoPath:filePath];
     [self loadFile:file intoPath:filePath];
 
 
-    if ([self.delegate respondsToSelector:@selector(operationWithProgressInformationStarted)])
-        [self.delegate operationWithProgressInformationStarted];
-
+    dispatch_async(dispatch_get_main_queue(), ^{
+        if ([self.delegate respondsToSelector:@selector(operationWithProgressInformationStarted)])
+            [self.delegate operationWithProgressInformationStarted];
+    });
     _downloadInProgress = YES;
     _downloadInProgress = YES;
 }
 }
 #endif
 #endif
@@ -263,8 +264,11 @@
         }
         }
 
 
         CGFloat progress = (CGFloat)bytesReceived / (CGFloat)expectedTotalBytes;
         CGFloat progress = (CGFloat)bytesReceived / (CGFloat)expectedTotalBytes;
-        if ([self.delegate respondsToSelector:@selector(currentProgressInformation:)])
-            [self.delegate currentProgressInformation:progress];
+
+        dispatch_async(dispatch_get_main_queue(), ^{
+            if ([self.delegate respondsToSelector:@selector(currentProgressInformation:)])
+                [self.delegate currentProgressInformation:progress];
+        });
     };
     };
 
 
     [[BoxSDK sharedSDK].filesManager downloadFileWithID:file.modelID outputStream:outputStream requestBuilder:nil success:successBlock failure:failureBlock progress:progressBlock];
     [[BoxSDK sharedSDK].filesManager downloadFileWithID:file.modelID outputStream:outputStream requestBuilder:nil success:successBlock failure:failureBlock progress:progressBlock];
@@ -292,8 +296,11 @@
     [formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
     [formatter setTimeZone:[NSTimeZone timeZoneForSecondsFromGMT:0]];
 
 
     NSString *remainingTime = [formatter stringFromDate:date];
     NSString *remainingTime = [formatter stringFromDate:date];
-    if ([self.delegate respondsToSelector:@selector(updateRemainingTime:)])
-        [self.delegate updateRemainingTime:remainingTime];
+
+    dispatch_async(dispatch_get_main_queue(), ^{
+        if ([self.delegate respondsToSelector:@selector(updateRemainingTime:)])
+            [self.delegate updateRemainingTime:remainingTime];
+    });
 }
 }
 
 
 - (void)downloadSuccessful
 - (void)downloadSuccessful
@@ -307,8 +314,10 @@
     [[NSNotificationCenter defaultCenter] postNotificationName:NSNotification.VLCNewFileAddedNotification
     [[NSNotificationCenter defaultCenter] postNotificationName:NSNotification.VLCNewFileAddedNotification
                                                         object:self];
                                                         object:self];
 #endif
 #endif
-    if ([self.delegate respondsToSelector:@selector(operationWithProgressInformationStopped)])
-        [self.delegate operationWithProgressInformationStopped];
+    dispatch_async(dispatch_get_main_queue(), ^{
+        if ([self.delegate respondsToSelector:@selector(operationWithProgressInformationStopped)])
+            [self.delegate operationWithProgressInformationStopped];
+    });
     _downloadInProgress = NO;
     _downloadInProgress = NO;
 
 
     [self _triggerNextDownload];
     [self _triggerNextDownload];
@@ -317,8 +326,10 @@
 - (void)downloadFailedWithError:(NSError*)error
 - (void)downloadFailedWithError:(NSError*)error
 {
 {
     APLog(@"BoxFile download failed with error %li", (long)error.code);
     APLog(@"BoxFile download failed with error %li", (long)error.code);
-    if ([self.delegate respondsToSelector:@selector(operationWithProgressInformationStopped)])
-        [self.delegate operationWithProgressInformationStopped];
+    dispatch_async(dispatch_get_main_queue(), ^{
+        if ([self.delegate respondsToSelector:@selector(operationWithProgressInformationStopped)])
+            [self.delegate operationWithProgressInformationStopped];
+    });
     _downloadInProgress = NO;
     _downloadInProgress = NO;
 
 
     [self _triggerNextDownload];
     [self _triggerNextDownload];

+ 2 - 1
Sources/VLCBoxTableViewController.m

@@ -276,7 +276,8 @@
     [ubiquitousStore setString:token forKey:kVLCStoreBoxCredentials];
     [ubiquitousStore setString:token forKey:kVLCStoreBoxCredentials];
     [ubiquitousStore synchronize];
     [ubiquitousStore synchronize];
     self.authorizationInProgress = YES;
     self.authorizationInProgress = YES;
-    [self updateViewAfterSessionChange];
+    [self performSelectorOnMainThread:@selector(updateViewAfterSessionChange)
+                           withObject:nil waitUntilDone:NO];
     self.authorizationInProgress = NO;
     self.authorizationInProgress = NO;
 }
 }