RCTNetworkTask.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*
  2. * Copyright (c) Facebook, Inc. and its affiliates.
  3. *
  4. * This source code is licensed under the MIT license found in the
  5. * LICENSE file in the root directory of this source tree.
  6. */
  7. #import <Foundation/Foundation.h>
  8. #import <React/RCTURLRequestDelegate.h>
  9. #import <React/RCTURLRequestHandler.h>
  10. typedef void (^RCTURLRequestCompletionBlock)(NSURLResponse *response, NSData *data, NSError *error);
  11. typedef void (^RCTURLRequestCancellationBlock)(void);
  12. typedef void (^RCTURLRequestIncrementalDataBlock)(NSData *data, int64_t progress, int64_t total);
  13. typedef void (^RCTURLRequestProgressBlock)(int64_t progress, int64_t total);
  14. typedef void (^RCTURLRequestResponseBlock)(NSURLResponse *response);
  15. typedef NS_ENUM(NSInteger, RCTNetworkTaskStatus) {
  16. RCTNetworkTaskPending = 0,
  17. RCTNetworkTaskInProgress,
  18. RCTNetworkTaskFinished,
  19. };
  20. @interface RCTNetworkTask : NSObject <RCTURLRequestDelegate>
  21. @property (nonatomic, readonly) NSURLRequest *request;
  22. @property (nonatomic, readonly) NSNumber *requestID;
  23. @property (nonatomic, readonly, weak) id requestToken;
  24. @property (nonatomic, readonly) NSURLResponse *response;
  25. @property (nonatomic, copy) RCTURLRequestCompletionBlock completionBlock;
  26. @property (nonatomic, copy) RCTURLRequestProgressBlock downloadProgressBlock;
  27. @property (nonatomic, copy) RCTURLRequestIncrementalDataBlock incrementalDataBlock;
  28. @property (nonatomic, copy) RCTURLRequestResponseBlock responseBlock;
  29. @property (nonatomic, copy) RCTURLRequestProgressBlock uploadProgressBlock;
  30. @property (nonatomic, readonly) RCTNetworkTaskStatus status;
  31. - (instancetype)initWithRequest:(NSURLRequest *)request
  32. handler:(id<RCTURLRequestHandler>)handler
  33. callbackQueue:(dispatch_queue_t)callbackQueue NS_DESIGNATED_INITIALIZER;
  34. - (void)start;
  35. - (void)cancel;
  36. @end