最近使用阿里云的oss 上传文件遇到的问题
解决方式 外层加了队列,本文主要写线程和信号量 持续更新
dispatch_async(dispatch_get_global_queue(0, 0), ^{
// 分块上传
[upload multipartUpload:videoPath objectKey:objectKeyName];
if([[self viewController] respondsToSelector:@selector(creatBackViewForUpdatePress)]){
[[self viewController] performSelector:@selector(creatBackViewForUpdatePress) withObject:nil];
}
});
信号量 网络请求的顺序 :
先上代码
-(void)loadData{
WS(wSelf)
if (!ISNETWORK) {
[self showBlank:HXQBlankNoNetwork BlankBlock:^(HXQBlankType blankType) {
[wSelf loadData];
}];
[self.tableView.mj_header endRefreshing];
return;
}
dispatch_group_t group = dispatch_group_create();
NSMutableArray<HXQADVModel*>* tempAdvList = [[NSMutableArray alloc] init];
NSMutableArray<HXQQuestionModel*>* tempQuestionList = [[NSMutableArray alloc] init];
NSMutableArray<HXQFunActivityModel*>* tempActivityList = [[NSMutableArray alloc] init];
NSMutableArray<HXQStarWarsListModel*>* tempStarWarsList = [[NSMutableArray alloc] init];
dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
// 顶部广告
[HttpRequestUtil GET:Action_Home_Adv parameters:@{@"spaceId":@"4"} finished:^(AjaxResult *result) {
if (result.code == AjaxResultStateSuccess) {
NSArray* advArray = result.datas;
for (NSDictionary* diction in advArray) {
HXQADVModel* advModel = [HXQADVModel mj_objectWithKeyValues:diction];
[tempAdvList addObject:advModel];
}
}
dispatch_semaphore_signal(sema);
}];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
});
if ([self isLogin]) {
dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
[HttpRequestUtil GET:Action_NewQuestion_UserInfo parameters:@{@"userId":[UserModel getCurrentUserFromLocal].userId} finished:^(AjaxResult *result) {
if (result.code == AjaxResultStateSuccess) {
DLog(@"%@",result.datas);
self.userInfoModel = [HXQNQUserInfoModel mj_objectWithKeyValues:result.datas];
}
dispatch_semaphore_signal(sema);
}];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
});
}
dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
// 答题
[HttpRequestUtil GET:Answer_Submit_GetQuestionRepositorys parameters:@{@"count":@(20)} finished:^(AjaxResult *result) {
if (result.code == AjaxResultStateSuccess) {
NSArray* questionArray = result.datas;
for (NSDictionary* diction in questionArray) {
HXQQuestionModel* advModel = [HXQQuestionModel mj_objectWithKeyValues:diction];
[tempQuestionList addObject:advModel];
}
}
dispatch_semaphore_signal(sema);
}];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
});
dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
// 投票
[HttpRequestUtil GET:Answer_Submit_activity parameters:@{@"page":@"0",@"count":@"100",@"type":@"0"} finished:^(AjaxResult *result) {
if (result.code == AjaxResultStateSuccess) {
NSDictionary* dic = [NSJSONSerialization JSONObjectWithData:result.originDatas options:NSJSONReadingMutableContainers error:nil];
NSArray* voteArray = result.datas;
for (NSDictionary* diction in voteArray) {
HXQFunActivityModel* model = [HXQFunActivityModel mj_objectWithKeyValues:diction];
model.handleTime = [(NSNumber*)[dic objectForKey:@"handleTime"] integerValue];
[tempActivityList addObject:model];
}
}
dispatch_semaphore_signal(sema);
}];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
});
dispatch_group_async(group, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
// 星战
[HttpRequestUtil GET:Action_Home_Info parameters:@{@"page":@"0",@"count":@"1"} finished:^(AjaxResult *result) {
if (result.code == AjaxResultStateSuccess) {
NSArray* starWarsArray = [result.datas objectForKey:@"list"];
for (NSDictionary* diction in starWarsArray) {
HXQStarWarsListModel* model = [HXQStarWarsListModel mj_objectWithKeyValues:diction];
[tempStarWarsList addObject:model];
}
}
dispatch_semaphore_signal(sema);
}];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
});
dispatch_group_notify(group, dispatch_get_main_queue(), ^{
//刷新界面
[self.advList removeAllObjects];
[self.questionList removeAllObjects];
[self.activityList removeAllObjects];
[self.starWarsList removeAllObjects];
[self.dataList removeAllObjects];
[self.advList addObjectsFromArray:tempAdvList];
if (self.advList.count>0) {
NSMutableArray* advArray = [[NSMutableArray alloc] init];
for (HXQADVModel* model in self.advList) {
[advArray addObject:APP_URL(model.img)];
}
self.headerView.imageURLStringsGroup = advArray;
[self.tableView setTableHeaderView:self.headerView];
}else
{
UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 0)];
[self.tableView setTableHeaderView:view];
}
[self.questionList addObjectsFromArray:tempQuestionList];
[self.activityList addObjectsFromArray:tempActivityList];
[self.starWarsList addObjectsFromArray:tempStarWarsList];
if (self.questionList.count>0) {
[self.dataList addObject:self.questionList];
}
if (self.starWarsList.count>0) {
[self.dataList addObject:self.starWarsList];
}
if (self.activityList.count>0) {
[self.dataList addObject:self.activityList];
}
[self.tableView.mj_header endRefreshing];
if (self.dataList.count>0) {
[self hidenBlank];
[self.tableView reloadData];
[self.tableView setTableFooterView:self.footerView];
}else
{
[self.tableView reloadData];
[self showBlank:HXQBlankNoDataType BlankBlock:^(HXQBlankType blankType) {
[wSelf loadData];
}];
}
});
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· 探究高空视频全景AR技术的实现原理
· 理解Rust引用及其生命周期标识(上)
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库