Skip to content

Commit

Permalink
Merge pull request #1721 from matrix-org/nimau/fix-medialoader-runloo…
Browse files Browse the repository at this point in the history
…pmode

Fix an issue where the media download would not start until the end of the scroll
  • Loading branch information
nimau authored Feb 16, 2023
2 parents 0be841e + 10affca commit dce98fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
7 changes: 6 additions & 1 deletion MatrixSDK/Utils/Media/MXMediaLoader.m
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,12 @@ - (void)downloadMediaFromURL:(NSString *)url
request.HTTPBody = [NSJSONSerialization dataWithJSONObject:data options:0 error:nil];
}

downloadConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
// if we use the default settings the connection object will be scheduled in the NSDefaultRunLoopMode. That means that the connection is only executing the request when the app’s run loop is in NSDefaultRunLoopMode.
// Now, when a user touches the screen (e.g. to scroll a UIScrollView) the run loop’s mode will be switched to NSEventTrackingRunLoopMode. And now, that the run loop is not in NSDefaultRunMode anymore, the connection will not execute. The ugly effect of that is, that the download is blocked whenever the user touches the screen
// Setting the mode to NSRunLoopCommonModes allow the request to work in all modes (even NSEventTrackingRunLoopMode)
downloadConnection = [[NSURLConnection alloc] initWithRequest:request delegate:self startImmediately:NO];
[downloadConnection scheduleInRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
[downloadConnection start];
}

- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
Expand Down
1 change: 1 addition & 0 deletions changelog.d/pr-1721.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix an issue where MXMediaLoader would not start downloading until the end of the scroll.

0 comments on commit dce98fc

Please sign in to comment.