@@ -61,6 +61,11 @@ QCloudResponseSerializerBlock QCloudResponseObjectSerilizerBlock(Class modelClas
6161 return (id )(transformData.data );
6262 };
6363
64+ @interface QCloudBizHTTPRequest ()
65+ @property (nonatomic ,strong ,nullable )dispatch_semaphore_t semaphore;
66+ @end
67+
68+
6469@implementation QCloudBizHTTPRequest
6570
6671- (instancetype )init {
@@ -108,7 +113,7 @@ - (QCloudSignatureFields *)signatureFields {
108113
109114- (BOOL )prepareInvokeURLRequest : (NSMutableURLRequest *)urlRequest error : (NSError *__autoreleasing *)error {
110115 // NSAssert(self.runOnService, @"RUN ON SERVICE is nil%@", self.runOnService);
111- __block dispatch_semaphore_t semaphore = dispatch_semaphore_create (0 );
116+ self. semaphore = dispatch_semaphore_create (0 );
112117 __block NSError *localError;
113118 __block BOOL isSigned;
114119 dispatch_async (dispatch_get_global_queue (DISPATCH_QUEUE_PRIORITY_HIGH, 0 ), ^{
@@ -141,11 +146,12 @@ - (BOOL)prepareInvokeURLRequest:(NSMutableURLRequest *)urlRequest error:(NSError
141146 // null authorization
142147 }
143148 }
144- dispatch_semaphore_signal (semaphore);
149+ dispatch_semaphore_signal (self.semaphore );
150+ self.semaphore = nil ;
145151 }];
146152 });
147153
148- dispatch_semaphore_wait (semaphore, dispatch_time (DISPATCH_TIME_NOW, 15 * NSEC_PER_SEC));
154+ dispatch_semaphore_wait (self. semaphore , dispatch_time (DISPATCH_TIME_NOW, 15 * NSEC_PER_SEC));
149155 if (localError) {
150156 if (NULL != error) {
151157 *error = localError;
@@ -177,6 +183,14 @@ - (void)loadQCloudSignature {
177183 NSData *md5data = [NSData dataWithBytes: result length: CC_MD5_DIGEST_LENGTH];
178184 return [md5data base64EncodedStringWithOptions: 0 ];
179185}
186+
187+ - (void )dealloc {
188+ if (self.semaphore ) {
189+ dispatch_semaphore_signal (self.semaphore );
190+ self.semaphore = nil ;
191+ }
192+ }
193+
180194- (void )setCOSServerSideEncyption {
181195 self.customHeaders [@" x-cos-server-side-encryption" ] = @" AES256" ;
182196}
0 commit comments