Commit aabf284e by pierce

fixed 首次安装开播可能崩溃的问题

parent 6df54f9b
...@@ -202,138 +202,144 @@ ...@@ -202,138 +202,144 @@
[[NSFileManager defaultManager] removeItemAtPath:bytedanceResource error:nil]; [[NSFileManager defaultManager] removeItemAtPath:bytedanceResource error:nil];
} }
NSString *bdurl = FUSLiveHelper.shareInstance.livePushConfig.bdurl; dispatch_async(dispatch_get_global_queue(0, 0), ^{
NSString *bdurlmd5 = FUSLiveHelper.shareInstance.livePushConfig.bdurlmd5;
[FUSResourceDownloader.shareInstance fus_removeTaskKeyWithDownloadUrl:bdurl md5:bdurlmd5];
NSString *licbag = FUSLiveHelper.shareInstance.livePushConfig.licbag;
NSString *licbagmd5 = FUSLiveHelper.shareInstance.livePushConfig.licbagmd5;
[FUSResourceDownloader.shareInstance fus_removeTaskKeyWithDownloadUrl:licbag md5:licbagmd5];
FUSDownloadResourceModel *downloadModel = [[FUSDownloadResourceModel alloc] init];
downloadModel.resourceUrl = FUSLiveHelper.shareInstance.livePushConfig.bdurl;
downloadModel.md5 = FUSLiveHelper.shareInstance.livePushConfig.bdurlmd5;
downloadModel.downloadPriority = NSOperationQueuePriorityVeryHigh;
downloadModel.unzipPath = FUSBeautyHelper.shareInstance.beautyConfig.beautyResourcePath;
FUSDownloadResourceModel *licbagDownloadModel = [[FUSDownloadResourceModel alloc] init];
licbagDownloadModel.resourceUrl = FUSLiveHelper.shareInstance.livePushConfig.licbag;
licbagDownloadModel.md5 = FUSLiveHelper.shareInstance.livePushConfig.licbagmd5;
licbagDownloadModel.downloadPriority = NSOperationQueuePriorityVeryHigh;
licbagDownloadModel.unzipPath = FUSBeautyHelper.shareInstance.beautyConfig.beautyResourceLicBagPath;
__block BOOL hasCancelLoading = NO;
FUSResourceDownloadingView *loadingView = [[FUSResourceDownloadingView alloc] initWithFrame:UIView.fus_screenFrame];
loadingView.tapToCloseHandler = ^{
hasCancelLoading = YES;
};
[[UIApplication sharedApplication].keyWindow addSubview:loadingView];
__weak typeof(loadingView) weakLoadingView = loadingView;
__weak typeof(self) weakSelf = self;
dispatch_group_t group = dispatch_group_create();
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
__block CGFloat resourceProgress = 0;
__block CGFloat licbagProgress = 0;
dispatch_group_enter(group);
__block BOOL hasLeaveLivePushConfig = NO;
downloadModel.succeedHandler = ^(NSString * _Nonnull filePath) {
if (hasLeaveLivePushConfig) { NSString *bdurl = FUSLiveHelper.shareInstance.livePushConfig.bdurl;
return; NSString *bdurlmd5 = FUSLiveHelper.shareInstance.livePushConfig.bdurlmd5;
} [FUSResourceDownloader.shareInstance fus_removeTaskKeyWithDownloadUrl:bdurl md5:bdurlmd5];
hasLeaveLivePushConfig = YES;
dispatch_group_leave(group);
};
downloadModel.failedHandler = ^(NSString * _Nonnull msg, NSInteger code) {
if (hasLeaveLivePushConfig) { NSString *licbag = FUSLiveHelper.shareInstance.livePushConfig.licbag;
return; NSString *licbagmd5 = FUSLiveHelper.shareInstance.livePushConfig.licbagmd5;
}
hasLeaveLivePushConfig = YES; [FUSResourceDownloader.shareInstance fus_removeTaskKeyWithDownloadUrl:licbag md5:licbagmd5];
dispatch_group_leave(group);
dispatch_async(dispatch_get_main_queue(), ^{
[FUSDialogView fus_showDialog:msg];
});
};
downloadModel.progresshandler = ^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
dispatch_async(dispatch_get_main_queue(), ^{ dispatch_async(dispatch_get_main_queue(), ^{
if (hasLeaveLivePushConfig) {
return; FUSDownloadResourceModel *downloadModel = [[FUSDownloadResourceModel alloc] init];
} downloadModel.resourceUrl = FUSLiveHelper.shareInstance.livePushConfig.bdurl;
if (weakLoadingView) { downloadModel.md5 = FUSLiveHelper.shareInstance.livePushConfig.bdurlmd5;
CGFloat progress = 0; downloadModel.downloadPriority = NSOperationQueuePriorityVeryHigh;
if (totalBytesRead > 0 && totalBytesExpectedToRead > 0) { downloadModel.unzipPath = FUSBeautyHelper.shareInstance.beautyConfig.beautyResourcePath;
progress = (CGFloat)totalBytesRead / (CGFloat)totalBytesExpectedToRead;
FUSDownloadResourceModel *licbagDownloadModel = [[FUSDownloadResourceModel alloc] init];
licbagDownloadModel.resourceUrl = FUSLiveHelper.shareInstance.livePushConfig.licbag;
licbagDownloadModel.md5 = FUSLiveHelper.shareInstance.livePushConfig.licbagmd5;
licbagDownloadModel.downloadPriority = NSOperationQueuePriorityVeryHigh;
licbagDownloadModel.unzipPath = FUSBeautyHelper.shareInstance.beautyConfig.beautyResourceLicBagPath;
__block BOOL hasCancelLoading = NO;
FUSResourceDownloadingView *loadingView = [[FUSResourceDownloadingView alloc] initWithFrame:UIView.fus_screenFrame];
loadingView.tapToCloseHandler = ^{
hasCancelLoading = YES;
};
[[UIApplication sharedApplication].keyWindow addSubview:loadingView];
__weak typeof(loadingView) weakLoadingView = loadingView;
__weak typeof(self) weakSelf = self;
dispatch_group_t group = dispatch_group_create();
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
__block CGFloat resourceProgress = 0;
__block CGFloat licbagProgress = 0;
dispatch_group_enter(group);
__block BOOL hasLeaveLivePushConfig = NO;
downloadModel.succeedHandler = ^(NSString * _Nonnull filePath) {
if (hasLeaveLivePushConfig) {
return;
} }
resourceProgress = 0.9 * progress; hasLeaveLivePushConfig = YES;
[weakLoadingView fus_setprogress:resourceProgress + licbagProgress]; dispatch_group_leave(group);
} else { };
FUSLogInfo(@"");
} downloadModel.failedHandler = ^(NSString * _Nonnull msg, NSInteger code) {
});
}; if (hasLeaveLivePushConfig) {
return;
dispatch_group_enter(group);
__block BOOL hasLeave = NO;
licbagDownloadModel.succeedHandler = ^(NSString * _Nonnull filePath) {
if (hasLeave) {
return;
}
hasLeave = YES;
dispatch_group_leave(group);
};
licbagDownloadModel.failedHandler = ^(NSString * _Nonnull msg, NSInteger code) {
if (hasLeave) {
return;
}
hasLeave = YES;
dispatch_group_leave(group);
dispatch_async(dispatch_get_main_queue(), ^{
[FUSDialogView fus_showDialog:msg];
});
};
licbagDownloadModel.progresshandler = ^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
dispatch_async(dispatch_get_main_queue(), ^{
if (hasLeave) {
return;
}
if (weakLoadingView) {
CGFloat progress = 0;
if (totalBytesRead > 0 && totalBytesExpectedToRead > 0) {
progress = (CGFloat)totalBytesRead / (CGFloat)totalBytesExpectedToRead;
} }
licbagProgress = 0.1 * progress; hasLeaveLivePushConfig = YES;
[weakLoadingView fus_setprogress:resourceProgress + licbagProgress]; dispatch_group_leave(group);
} else { dispatch_async(dispatch_get_main_queue(), ^{
FUSLogInfo(@""); [FUSDialogView fus_showDialog:msg];
} });
}); };
};
downloadModel.progresshandler = ^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
dispatch_group_notify(group, queue, ^{ dispatch_async(dispatch_get_main_queue(), ^{
// 做一小会儿延迟,保证文件已经写入完成 if (hasLeaveLivePushConfig) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)), return;
dispatch_get_main_queue(), ^{ }
if (!hasCancelLoading) { if (weakLoadingView) {
[weakSelf fus_pushLive]; CGFloat progress = 0;
} if (totalBytesRead > 0 && totalBytesExpectedToRead > 0) {
[weakLoadingView removeFromSuperview]; progress = (CGFloat)totalBytesRead / (CGFloat)totalBytesExpectedToRead;
}
resourceProgress = 0.9 * progress;
[weakLoadingView fus_setprogress:resourceProgress + licbagProgress];
} else {
FUSLogInfo(@"");
}
});
};
dispatch_group_enter(group);
__block BOOL hasLeave = NO;
licbagDownloadModel.succeedHandler = ^(NSString * _Nonnull filePath) {
if (hasLeave) {
return;
}
hasLeave = YES;
dispatch_group_leave(group);
};
licbagDownloadModel.failedHandler = ^(NSString * _Nonnull msg, NSInteger code) {
if (hasLeave) {
return;
}
hasLeave = YES;
dispatch_group_leave(group);
dispatch_async(dispatch_get_main_queue(), ^{
[FUSDialogView fus_showDialog:msg];
});
};
licbagDownloadModel.progresshandler = ^(NSUInteger bytesRead, long long totalBytesRead, long long totalBytesExpectedToRead) {
dispatch_async(dispatch_get_main_queue(), ^{
if (hasLeave) {
return;
}
if (weakLoadingView) {
CGFloat progress = 0;
if (totalBytesRead > 0 && totalBytesExpectedToRead > 0) {
progress = (CGFloat)totalBytesRead / (CGFloat)totalBytesExpectedToRead;
}
licbagProgress = 0.1 * progress;
[weakLoadingView fus_setprogress:resourceProgress + licbagProgress];
} else {
FUSLogInfo(@"");
}
});
};
dispatch_group_notify(group, queue, ^{
// 做一小会儿延迟,保证文件已经写入完成
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.2 * NSEC_PER_SEC)),
dispatch_get_main_queue(), ^{
if (!hasCancelLoading) {
[weakSelf fus_pushLive];
}
[weakLoadingView removeFromSuperview];
});
});
[FUSResourceDownloader.shareInstance fus_addDownloadResource:downloadModel];
[FUSResourceDownloader.shareInstance fus_addDownloadResource:licbagDownloadModel];
}); });
}); });
[FUSResourceDownloader.shareInstance fus_addDownloadResource:downloadModel];
[FUSResourceDownloader.shareInstance fus_addDownloadResource:licbagDownloadModel];
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment