1
- //
2
- // VydiaRNFileUploader.m
3
- // Vydia
4
- //
5
- // Created by Kenneth Leland on 12/8/16.
6
- // Copyright © 2016 Vydia. All rights reserved.
7
- //
8
-
9
1
#import < Foundation/Foundation.h>
10
2
#import < MobileCoreServices/MobileCoreServices.h>
11
3
#import < React/RCTEventEmitter.h>
@@ -24,9 +16,13 @@ @implementation VydiaRNFileUploader
24
16
@synthesize bridge = _bridge;
25
17
static int uploadId = 0 ;
26
18
static RCTEventEmitter* staticEventEmitter = nil ;
27
- static NSString *BACKGROUND_SESSION_ID = @" VydiaRNFileUploader " ;
19
+ static NSString *BACKGROUND_SESSION_ID = @" ReactNativeBackgroundUpload " ;
28
20
NSURLSession *_urlSession = nil ;
29
21
22
+ + (BOOL )requiresMainQueueSetup {
23
+ return NO ;
24
+ }
25
+
30
26
-(id ) init {
31
27
self = [super init ];
32
28
if (self) {
@@ -88,7 +84,9 @@ - (void)_sendEventWithName:(NSString *)eventName body:(id)body {
88
84
}
89
85
}
90
86
91
- // Borrowed from http://stackoverflow.com/questions/2439020/wheres-the-iphone-mime-type-database
87
+ /*
88
+ Borrowed from http://stackoverflow.com/questions/2439020/wheres-the-iphone-mime-type-database
89
+ */
92
90
- (NSString *)guessMIMETypeFromFileName : (NSString *)fileName {
93
91
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag (kUTTagClassFilenameExtension , (__bridge CFStringRef)[fileName pathExtension ], NULL );
94
92
CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass (UTI, kUTTagClassMIMEType );
@@ -149,9 +147,9 @@ - (NSString *)guessMIMETypeFromFileName: (NSString *)fileName {
149
147
[request setHTTPBody: httpBody];
150
148
151
149
// I am sorry about warning, but Upload tasks from NSData are not supported in background sessions.
152
- uploadTask = [[self urlSession: thisUploadId ] uploadTaskWithRequest: request fromData: nil ];
150
+ uploadTask = [[self urlSession ] uploadTaskWithRequest: request fromData: nil ];
153
151
} else {
154
- uploadTask = [[self urlSession: thisUploadId ] uploadTaskWithRequest: request fromFile: [NSURL URLWithString: fileURI]];
152
+ uploadTask = [[self urlSession ] uploadTaskWithRequest: request fromFile: [NSURL URLWithString: fileURI]];
155
153
}
156
154
157
155
uploadTask.taskDescription = customUploadId ? customUploadId : [NSString stringWithFormat: @" %i " , thisUploadId];
@@ -206,10 +204,10 @@ - (NSData *)createBodyWithBoundary:(NSString *)boundary
206
204
return httpBody;
207
205
}
208
206
209
- - (NSURLSession *)urlSession : ( int ) thisUploadId {
210
- if (_urlSession == nil ) {
211
- NSURLSessionConfiguration *sessionConfigurationt = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier: BACKGROUND_SESSION_ID];
212
- _urlSession = [NSURLSession sessionWithConfiguration: sessionConfigurationt delegate: self delegateQueue: nil ];
207
+ - (NSURLSession *)urlSession {
208
+ if (_urlSession == nil ) {
209
+ NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier: BACKGROUND_SESSION_ID];
210
+ _urlSession = [NSURLSession sessionWithConfiguration: sessionConfiguration delegate: self delegateQueue: nil ];
213
211
}
214
212
return _urlSession;
215
213
}
0 commit comments