mirror of
https://github.com/zhigang1992/react-native.git
synced 2026-02-07 17:27:56 +08:00
Summary: public There was a race condition issue in RCTDownLoadTask whereby the request handler would sometimes call one of the delegate methods before setup was complete, causing an error to be logged because the request token had not been set, and causing te request to fail because the class was not yet set up. This diff fixes that issue by adding an explicit `start` method to RCTDownloadTask, and changing the setup order to allow for the request to call back immediately without this being treated as an error. Reviewed By: tadeuzagallo Differential Revision: D2553628 fb-gh-sync-id: 5ca4e791574a632ccbf2e873e28ac88bffdf851d
42 lines
1.7 KiB
Objective-C
42 lines
1.7 KiB
Objective-C
/**
|
|
* Copyright (c) 2015-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*/
|
|
|
|
#import <Foundation/Foundation.h>
|
|
|
|
#import "RCTURLRequestDelegate.h"
|
|
#import "RCTURLRequestHandler.h"
|
|
|
|
typedef void (^RCTURLRequestCompletionBlock)(NSURLResponse *response, NSData *data, NSError *error);
|
|
typedef void (^RCTURLRequestCancellationBlock)(void);
|
|
typedef void (^RCTURLRequestIncrementalDataBlock)(NSData *data);
|
|
typedef void (^RCTURLRequestProgressBlock)(int64_t progress, int64_t total);
|
|
typedef void (^RCTURLRequestResponseBlock)(NSURLResponse *response);
|
|
|
|
@interface RCTDownloadTask : NSObject <RCTURLRequestDelegate>
|
|
|
|
@property (nonatomic, readonly) NSURLRequest *request;
|
|
@property (nonatomic, readonly) NSNumber *requestID;
|
|
@property (nonatomic, readonly) id requestToken;
|
|
@property (nonatomic, readonly) NSURLResponse *response;
|
|
@property (nonatomic, readonly) RCTURLRequestCompletionBlock completionBlock;
|
|
|
|
@property (nonatomic, copy) RCTURLRequestProgressBlock downloadProgressBlock;
|
|
@property (nonatomic, copy) RCTURLRequestIncrementalDataBlock incrementalDataBlock;
|
|
@property (nonatomic, copy) RCTURLRequestResponseBlock responseBlock;
|
|
@property (nonatomic, copy) RCTURLRequestProgressBlock uploadProgressBlock;
|
|
|
|
- (instancetype)initWithRequest:(NSURLRequest *)request
|
|
handler:(id<RCTURLRequestHandler>)handler
|
|
completionBlock:(RCTURLRequestCompletionBlock)completionBlock NS_DESIGNATED_INITIALIZER;
|
|
|
|
- (void)start;
|
|
- (void)cancel;
|
|
|
|
@end
|