Skip to content

Commit 187bbce

Browse files
committed
Fixed retaining issues while waiting for video URL
1 parent 4f3ac8f commit 187bbce

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

Pod/Classes/MWPhoto.m

+4-1
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,13 @@ - (void)getVideoURL:(void (^)(NSURL *url))completion {
122122
[self cancelVideoRequest]; // Cancel any existing
123123
PHVideoRequestOptions *options = [PHVideoRequestOptions new];
124124
options.networkAccessAllowed = YES;
125+
typeof(self) __weak weakSelf = self;
125126
_assetVideoRequestID = [[PHImageManager defaultManager] requestAVAssetForVideo:_asset options:options resultHandler:^(AVAsset *asset, AVAudioMix *audioMix, NSDictionary *info) {
126127

127128
// dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 3 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ // Testing
128-
_assetVideoRequestID = PHInvalidImageRequestID;
129+
typeof(self) strongSelf = weakSelf;
130+
if (!strongSelf) return;
131+
strongSelf->_assetVideoRequestID = PHInvalidImageRequestID;
129132
if ([asset isKindOfClass:[AVURLAsset class]]) {
130133
completion(((AVURLAsset *)asset).URL);
131134
} else {

Pod/Classes/MWPhotoBrowser.m

+3-1
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,9 @@ - (void)playVideoAtIndex:(NSUInteger)index {
12021202
[photo getVideoURL:^(NSURL *url) {
12031203
dispatch_async(dispatch_get_main_queue(), ^{
12041204
// If the video is not playing anymore then bail
1205-
if (_currentVideoIndex != index || !_viewIsActive) {
1205+
typeof(self) strongSelf = weakSelf;
1206+
if (!strongSelf) return;
1207+
if (strongSelf->_currentVideoIndex != index || !strongSelf->_viewIsActive) {
12061208
return;
12071209
}
12081210
if (url) {

0 commit comments

Comments
 (0)