@@ -127,46 +127,46 @@ - (void)enqueue {
127127 // Process fetches
128128 self.state = FIRStorageTaskStateRunning;
129129
130- #pragma clang diagnostic push
131- #pragma clang diagnostic ignored "-Warc-retain-cycles"
132130 _fetcherCompletion = ^(NSData *_Nullable data, NSError *_Nullable error) {
133- // Fire last progress updates
134- [self fireHandlersForStatus: FIRStorageTaskStatusProgress snapshot: self .snapshot];
135-
136- // Handle potential issues with upload
137- if (error) {
138- self.state = FIRStorageTaskStateFailed;
139- self.error = [FIRStorageErrors errorWithServerError: error reference: self .reference];
140- self.metadata = self->_uploadMetadata ;
141- [self fireHandlersForStatus: FIRStorageTaskStatusFailure snapshot: self .snapshot];
142- [self removeAllObservers ];
143- self->_fetcherCompletion = nil ;
144- return ;
131+ __strong FIRStorageUploadTask *strongSelf = weakSelf;
132+ if (strongSelf) {
133+ // Fire last progress updates
134+ [strongSelf fireHandlersForStatus: FIRStorageTaskStatusProgress snapshot: strongSelf.snapshot];
135+
136+ // Handle potential issues with upload
137+ if (error) {
138+ strongSelf.state = FIRStorageTaskStateFailed;
139+ strongSelf.error =
140+ [FIRStorageErrors errorWithServerError: error reference: strongSelf.reference];
141+ strongSelf.metadata = strongSelf->_uploadMetadata ;
142+ [strongSelf fireHandlersForStatus: FIRStorageTaskStatusFailure snapshot: strongSelf.snapshot];
143+ [strongSelf removeAllObservers ];
144+ strongSelf->_fetcherCompletion = nil ;
145+ return ;
146+ }
147+
148+ // Upload completed successfully, fire completion callbacks
149+ strongSelf.state = FIRStorageTaskStateSuccess;
150+
151+ NSDictionary *responseDictionary = [NSDictionary frs_dictionaryFromJSONData: data];
152+ if (responseDictionary) {
153+ FIRStorageMetadata *metadata =
154+ [[FIRStorageMetadata alloc ] initWithDictionary: responseDictionary];
155+ [metadata setType: FIRStorageMetadataTypeFile];
156+ strongSelf.metadata = metadata;
157+ } else {
158+ strongSelf.error = [FIRStorageErrors errorWithInvalidRequest: data];
159+ }
160+
161+ [strongSelf fireHandlersForStatus: FIRStorageTaskStatusSuccess snapshot: strongSelf.snapshot];
162+ [strongSelf removeAllObservers ];
163+ strongSelf->_fetcherCompletion = nil ;
145164 }
146-
147- // Upload completed successfully, fire completion callbacks
148- self.state = FIRStorageTaskStateSuccess;
149-
150- NSDictionary *responseDictionary = [NSDictionary frs_dictionaryFromJSONData: data];
151- if (responseDictionary) {
152- FIRStorageMetadata *metadata =
153- [[FIRStorageMetadata alloc ] initWithDictionary: responseDictionary];
154- [metadata setType: FIRStorageMetadataTypeFile];
155- self.metadata = metadata;
156- } else {
157- self.error = [FIRStorageErrors errorWithInvalidRequest: data];
158- }
159-
160- [self fireHandlersForStatus: FIRStorageTaskStatusSuccess snapshot: self .snapshot];
161- [self removeAllObservers ];
162- self->_fetcherCompletion = nil ;
163165 };
164- #pragma clang diagnostic pop
165166
166- [_uploadFetcher
167- beginFetchWithCompletionHandler: ^(NSData *_Nullable data, NSError *_Nullable error) {
168- weakSelf.fetcherCompletion (data, error);
169- }];
167+ [_uploadFetcher beginFetchWithCompletionHandler: ^(NSData *data, NSError *error) {
168+ weakSelf.fetcherCompletion (data, error);
169+ }];
170170}
171171
172172#pragma mark - Upload Management
0 commit comments