问题描述
ps 问题已解决,原因在末尾
在Macos应用中进行文件上传(系统版本10.14.5)
代码如下,通过AVFile
上传文件
AVFile *f = [AVFile fileWithLocalPath:file.srtPath error:&ferror];
EXIT_IF_ERROR(ferror);
dispatch_group_enter(group);
NSLog(@"Begin Upload %@",file.srtPath.lastPathComponent);//日志跟踪这里有执行到
[f uploadWithProgress:^(NSInteger percent) {
NSLog(@"Progress %@ %d",file.srtPath.lastPathComponent,percent);//这里不会回调
} completionHandler:^(BOOL succeeded, NSError * _Nullable error) {
//macos 系统这里也同样不会回调
EXIT_IF_ERROR(error);
file.srtCloudId = f.objectId;
file.srtCloudUrl = f.url;
[self saveStatus];
NSLog(@"Finished Upload %@",file.srtPath.lastPathComponent);
dispatch_group_leave(group);
}];
而且控制台有输出以下结果,表示文件上传成功了
------ BEGIN LeanCloud REST Response ------
path: /1.1/fileTokens
cost: 6244.242ms
response: {
bucket = TDWwApWr;
createdAt = "2020-06-10T13:50:32.350Z";
key = "aFXCLCRP5kptWCQZaJpNJ3A.ytenc";
"mime_type" = "application/octet-stream";
objectId = 5ee0e5289cba770009cd0514;
provider = qiniu;
token = "w6ZYeC-arS2makzcotrVJGjQvpsCQeHcPseFRDzJ:47xq6dUfIZalnWN8aPwY7cszsHI=:eyJpbnNlcnRPbmx5IjoxLCJzY29wZSI6IlREV3dBcFdyIiwibWltZUxpbWl0IjoiISIsImRlYWRsaW5lIjoxNTkxODAwNjMyfQ==";
"upload_url" = "https://upload.qiniup.com";
url = "http://file.yingyutingting.com/aFXCLCRP5kptWCQZaJpNJ3A.ytenc";
}
------ END --------------------------------
如题,控制台可以看到上传成功的文件
PS:我把同样的代码,创建了一个ios app,block同样没有回调
已解决
问题已找到,原因是AVFile的block回调都在主线程,而我在代码中用了dispatch_group
,并在主线程执行dispatch_group_wait(group, DISPATCH_TIME_FOREVER);
这样会导致主线程一直处于等待状态