aliyun / aliyun-oss-ios-sdk

iOS SDK for aliyun object storage service
Other
469 stars 321 forks source link

使用 NSOperationQueue管理图片上传队列,导致超时上传失败,是发生死锁了吗,如何解决? #367

Closed zhaozzq closed 10 months ago

zhaozzq commented 10 months ago

代码如下:

NSOperationQueue *queue = [[NSOperationQueue alloc] init];
queue.maxConcurrentOperationCount = 3;
__block BOOL hasError = NO;
for ( ... ) {
    [queue addOperationWithBlock:^{
                    OSSPutObjectRequest * put = [OSSPutObjectRequest new];
                    put.bucketName = APPENV;
                    put.objectKey = imgName;
                    put.uploadingData = UIImageJPEGRepresentation(image, 0.1);
                    OSSTask * putTask = [client putObject:put];
                    [putTask waitUntilFinished];
                    if (putTask.error) {
                        hasError = YES;
                    }
    }];
}
[queue waitUntilAllOperationsAreFinished];
zhaozzq commented 10 months ago

外层套了 dispatch_async(dispatch_get_global_queue(0, 0), ^{ })好了