Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Synchronized #7

Closed
wants to merge 10 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ios/RNFetchBlob.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
objects = {

/* Begin PBXBuildFile section */
8C4801A6200CF71700FED7ED /* RNFetchBlobRequest.m in Sources */ = {isa = PBXBuildFile; fileRef = 8C4801A5200CF71700FED7ED /* RNFetchBlobRequest.m */; };
A158F4271D052E49006FFD38 /* RNFetchBlobFS.m in Sources */ = {isa = PBXBuildFile; fileRef = A158F4261D052E49006FFD38 /* RNFetchBlobFS.m */; };
A158F42D1D0535BB006FFD38 /* RNFetchBlobConst.m in Sources */ = {isa = PBXBuildFile; fileRef = A158F42C1D0535BB006FFD38 /* RNFetchBlobConst.m */; };
A158F4301D0539DB006FFD38 /* RNFetchBlobNetwork.m in Sources */ = {isa = PBXBuildFile; fileRef = A158F42F1D0539DB006FFD38 /* RNFetchBlobNetwork.m */; };
Expand All @@ -29,6 +30,8 @@
/* End PBXCopyFilesBuildPhase section */

/* Begin PBXFileReference section */
8C4801A4200CF71700FED7ED /* RNFetchBlobRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNFetchBlobRequest.h; sourceTree = "<group>"; };
8C4801A5200CF71700FED7ED /* RNFetchBlobRequest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNFetchBlobRequest.m; sourceTree = "<group>"; };
A158F4261D052E49006FFD38 /* RNFetchBlobFS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = RNFetchBlobFS.m; sourceTree = "<group>"; };
A158F4281D052E57006FFD38 /* RNFetchBlobFS.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNFetchBlobFS.h; sourceTree = "<group>"; };
A158F4291D0534A9006FFD38 /* RNFetchBlobConst.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNFetchBlobConst.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -71,8 +74,10 @@
A1F950181D7E9134002A95A6 /* IOS7Polyfill.h */,
A1AAE2981D300E4D0051D11C /* RNFetchBlobReqBuilder.m */,
A1AAE2971D300E3E0051D11C /* RNFetchBlobReqBuilder.h */,
A158F42F1D0539DB006FFD38 /* RNFetchBlobNetwork.m */,
A158F42E1D0539CE006FFD38 /* RNFetchBlobNetwork.h */,
A158F42F1D0539DB006FFD38 /* RNFetchBlobNetwork.m */,
8C4801A4200CF71700FED7ED /* RNFetchBlobRequest.h */,
8C4801A5200CF71700FED7ED /* RNFetchBlobRequest.m */,
A158F42C1D0535BB006FFD38 /* RNFetchBlobConst.m */,
A158F4291D0534A9006FFD38 /* RNFetchBlobConst.h */,
A158F4281D052E57006FFD38 /* RNFetchBlobFS.h */,
Expand Down Expand Up @@ -149,6 +154,7 @@
buildActionMask = 2147483647;
files = (
A166D1AA1CE0647A00273590 /* RNFetchBlob.h in Sources */,
8C4801A6200CF71700FED7ED /* RNFetchBlobRequest.m in Sources */,
A158F42D1D0535BB006FFD38 /* RNFetchBlobConst.m in Sources */,
A158F4271D052E49006FFD38 /* RNFetchBlobFS.m in Sources */,
A158F4301D0539DB006FFD38 /* RNFetchBlobNetwork.m in Sources */,
Expand Down
1 change: 0 additions & 1 deletion ios/RNFetchBlob/RNFetchBlob.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
@property (retain) UIDocumentInteractionController * documentController;

+ (RCTBridge *)getRCTBridge;
+ (void) checkExpiredSessions;

@end

Expand Down
24 changes: 16 additions & 8 deletions ios/RNFetchBlob/RNFetchBlob.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ - (dispatch_queue_t) methodQueue {

+ (RCTBridge *)getRCTBridge
{
RCTRootView * rootView = [[UIApplication sharedApplication] keyWindow].rootViewController.view;
RCTRootView * rootView = (RCTRootView*) [[UIApplication sharedApplication] keyWindow].rootViewController.view;
return rootView.bridge;
}

Expand Down Expand Up @@ -96,8 +96,12 @@ - (NSDictionary *)constantsToExport
// send HTTP request
else
{
RNFetchBlobNetwork * utils = [[RNFetchBlobNetwork alloc] init];
[utils sendRequest:options contentLength:bodyLength bridge:self.bridge taskId:taskId withRequest:req callback:callback];
[[RNFetchBlobNetwork sharedInstance] sendRequest:options
contentLength:bodyLength
bridge:self.bridge
taskId:taskId
withRequest:req
callback:callback];
}
}];

Expand Down Expand Up @@ -128,8 +132,12 @@ - (NSDictionary *)constantsToExport
// send HTTP request
else
{
__block RNFetchBlobNetwork * utils = [[RNFetchBlobNetwork alloc] init];
[utils sendRequest:options contentLength:bodyLength bridge:self.bridge taskId:taskId withRequest:req callback:callback];
[[RNFetchBlobNetwork sharedInstance] sendRequest:options
contentLength:bodyLength
bridge:self.bridge
taskId:taskId
withRequest:req
callback:callback];
}
}];
}
Expand Down Expand Up @@ -488,7 +496,7 @@ - (NSDictionary *)constantsToExport

#pragma mark - net.cancelRequest
RCT_EXPORT_METHOD(cancelRequest:(NSString *)taskId callback:(RCTResponseSenderBlock)callback) {
[RNFetchBlobNetwork cancelRequest:taskId];
[[RNFetchBlobNetwork sharedInstance] cancelRequest:taskId];
callback(@[[NSNull null], taskId]);

}
Expand All @@ -498,14 +506,14 @@ - (NSDictionary *)constantsToExport
{

RNFetchBlobProgress * cfg = [[RNFetchBlobProgress alloc] initWithType:Download interval:interval count:count];
[RNFetchBlobNetwork enableProgressReport:taskId config:cfg];
[[RNFetchBlobNetwork sharedInstance] enableProgressReport:taskId config:cfg];
}

#pragma mark - net.enableUploadProgressReport
RCT_EXPORT_METHOD(enableUploadProgressReport:(NSString *)taskId interval:(nonnull NSNumber*)interval count:(nonnull NSNumber*)count)
{
RNFetchBlobProgress * cfg = [[RNFetchBlobProgress alloc] initWithType:Upload interval:interval count:count];
[RNFetchBlobNetwork enableUploadProgress:taskId config:cfg];
[[RNFetchBlobNetwork sharedInstance] enableUploadProgress:taskId config:cfg];
}

#pragma mark - fs.slice
Expand Down
56 changes: 28 additions & 28 deletions ios/RNFetchBlobConst.m
Original file line number Diff line number Diff line change
Expand Up @@ -7,38 +7,38 @@
//
#import "RNFetchBlobConst.h"

extern NSString *const FILE_PREFIX = @"RNFetchBlob-file://";
extern NSString *const ASSET_PREFIX = @"bundle-assets://";
extern NSString *const AL_PREFIX = @"assets-library://";
NSString *const FILE_PREFIX = @"RNFetchBlob-file://";
NSString *const ASSET_PREFIX = @"bundle-assets://";
NSString *const AL_PREFIX = @"assets-library://";

// fetch configs
extern NSString *const CONFIG_USE_TEMP = @"fileCache";
extern NSString *const CONFIG_FILE_PATH = @"path";
extern NSString *const CONFIG_FILE_EXT = @"appendExt";
extern NSString *const CONFIG_TRUSTY = @"trusty";
extern NSString *const CONFIG_INDICATOR = @"indicator";
extern NSString *const CONFIG_KEY = @"key";
extern NSString *const CONFIG_EXTRA_BLOB_CTYPE = @"binaryContentTypes";
NSString *const CONFIG_USE_TEMP = @"fileCache";
NSString *const CONFIG_FILE_PATH = @"path";
NSString *const CONFIG_FILE_EXT = @"appendExt";
NSString *const CONFIG_TRUSTY = @"trusty";
NSString *const CONFIG_INDICATOR = @"indicator";
NSString *const CONFIG_KEY = @"key";
NSString *const CONFIG_EXTRA_BLOB_CTYPE = @"binaryContentTypes";

extern NSString *const EVENT_STATE_CHANGE = @"RNFetchBlobState";
extern NSString *const EVENT_SERVER_PUSH = @"RNFetchBlobServerPush";
extern NSString *const EVENT_PROGRESS = @"RNFetchBlobProgress";
extern NSString *const EVENT_PROGRESS_UPLOAD = @"RNFetchBlobProgress-upload";
extern NSString *const EVENT_EXPIRE = @"RNFetchBlobExpire";
NSString *const EVENT_STATE_CHANGE = @"RNFetchBlobState";
NSString *const EVENT_SERVER_PUSH = @"RNFetchBlobServerPush";
NSString *const EVENT_PROGRESS = @"RNFetchBlobProgress";
NSString *const EVENT_PROGRESS_UPLOAD = @"RNFetchBlobProgress-upload";
NSString *const EVENT_EXPIRE = @"RNFetchBlobExpire";

extern NSString *const MSG_EVENT = @"RNFetchBlobMessage";
extern NSString *const MSG_EVENT_LOG = @"log";
extern NSString *const MSG_EVENT_WARN = @"warn";
extern NSString *const MSG_EVENT_ERROR = @"error";
extern NSString *const FS_EVENT_DATA = @"data";
extern NSString *const FS_EVENT_END = @"end";
extern NSString *const FS_EVENT_WARN = @"warn";
extern NSString *const FS_EVENT_ERROR = @"error";
NSString *const MSG_EVENT = @"RNFetchBlobMessage";
NSString *const MSG_EVENT_LOG = @"log";
NSString *const MSG_EVENT_WARN = @"warn";
NSString *const MSG_EVENT_ERROR = @"error";
NSString *const FS_EVENT_DATA = @"data";
NSString *const FS_EVENT_END = @"end";
NSString *const FS_EVENT_WARN = @"warn";
NSString *const FS_EVENT_ERROR = @"error";

extern NSString *const KEY_REPORT_PROGRESS = @"reportProgress";
extern NSString *const KEY_REPORT_UPLOAD_PROGRESS = @"reportUploadProgress";
NSString *const KEY_REPORT_PROGRESS = @"reportProgress";
NSString *const KEY_REPORT_UPLOAD_PROGRESS = @"reportUploadProgress";

// response type
extern NSString *const RESP_TYPE_BASE64 = @"base64";
extern NSString *const RESP_TYPE_UTF8 = @"utf8";
extern NSString *const RESP_TYPE_PATH = @"path";
NSString *const RESP_TYPE_BASE64 = @"base64";
NSString *const RESP_TYPE_UTF8 = @"utf8";
NSString *const RESP_TYPE_PATH = @"path";
4 changes: 2 additions & 2 deletions ios/RNFetchBlobFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
NSString * streamId;
}

@property (nonatomic) NSOutputStream * outStream;
@property (nonatomic) NSInputStream * inStream;
@property (nonatomic) NSOutputStream * _Nullable outStream;
@property (nonatomic) NSInputStream * _Nullable inStream;
@property (strong, nonatomic) RCTResponseSenderBlock callback;
@property (nonatomic) RCTBridge * bridge;
@property (nonatomic) NSString * encoding;
Expand Down
44 changes: 16 additions & 28 deletions ios/RNFetchBlobNetwork.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,52 +6,40 @@
// Copyright © 2016 wkh237. All rights reserved.
//

#ifndef RNFetchBlobNetwork_h
#define RNFetchBlobNetwork_h

#import <Foundation/Foundation.h>
#import "RNFetchBlobProgress.h"
#import "RNFetchBlobFS.h"
#import "RNFetchBlobRequest.h"

#if __has_include(<React/RCTAssert.h>)
#import <React/RCTBridgeModule.h>
#else
#import "RCTBridgeModule.h"
#endif

#ifndef RNFetchBlobNetwork_h
#define RNFetchBlobNetwork_h



typedef void(^CompletionHander)(NSURL * _Nullable location, NSURLResponse * _Nullable response, NSError * _Nullable error);
typedef void(^DataTaskCompletionHander) (NSData * _Nullable resp, NSURLResponse * _Nullable response, NSError * _Nullable error);

@interface RNFetchBlobNetwork : NSObject <NSURLSessionDelegate, NSURLSessionTaskDelegate, NSURLSessionDataDelegate>

@property (nullable, nonatomic) NSString * taskId;
@property (nonatomic) int expectedBytes;
@property (nonatomic) int receivedBytes;
@property (nonatomic) BOOL isServerPush;
@property (nullable, nonatomic) NSMutableData * respData;
@property (strong, nonatomic) RCTResponseSenderBlock callback;
@property (nullable, nonatomic) RCTBridge * bridge;
@property (nullable, nonatomic) NSDictionary * options;
@property (nullable, nonatomic) RNFetchBlobFS * fileStream;
@property (strong, nonatomic) CompletionHander fileTaskCompletionHandler;
@property (strong, nonatomic) DataTaskCompletionHander dataTaskCompletionHandler;
@property (nullable, nonatomic) NSError * error;

@property(nonnull, nonatomic) NSOperationQueue *taskQueue;
@property(nonnull, nonatomic) NSMapTable<NSString*, RNFetchBlobRequest*> * requestsTable;

+ (RNFetchBlobNetwork* _Nullable)sharedInstance;
+ (NSMutableDictionary * _Nullable ) normalizeHeaders:(NSDictionary * _Nullable)headers;
+ (void) cancelRequest:(NSString *)taskId;
+ (void) enableProgressReport:(NSString *) taskId;
+ (void) enableUploadProgress:(NSString *) taskId;
+ (void) emitExpiredTasks;

- (nullable id) init;
- (void) sendRequest;
- (void) sendRequest:(NSDictionary * _Nullable )options contentLength:(long)contentLength bridge:(RCTBridge * _Nullable)bridgeRef taskId:(NSString * _Nullable)taskId withRequest:(NSURLRequest * _Nullable)req callback:(_Nullable RCTResponseSenderBlock) callback;
+ (void) enableProgressReport:(NSString *) taskId config:(RNFetchBlobProgress *)config;
+ (void) enableUploadProgress:(NSString *) taskId config:(RNFetchBlobProgress *)config;

- (void) sendRequest:(NSDictionary * _Nullable )options
contentLength:(long)contentLength
bridge:(RCTBridge * _Nullable)bridgeRef
taskId:(NSString * _Nullable)taskId
withRequest:(NSURLRequest * _Nullable)req
callback:(_Nullable RCTResponseSenderBlock) callback;
- (void) cancelRequest:(NSString * _Nonnull)taskId;
- (void) enableProgressReport:(NSString * _Nonnull) taskId config:(RNFetchBlobProgress * _Nullable)config;
- (void) enableUploadProgress:(NSString * _Nonnull) taskId config:(RNFetchBlobProgress * _Nullable)config;


@end
Expand Down
Loading