Skip to content

Commit

Permalink
Merge pull request #61 from Vydia/remove-RN-warning
Browse files Browse the repository at this point in the history
Remove iOS console warning and cleanup .m file
  • Loading branch information
StevePotter committed Feb 2, 2018
2 parents 19c16f6 + 3d29d36 commit 6fbc204
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 17 deletions.
30 changes: 14 additions & 16 deletions ios/VydiaRNFileUploader.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
//
// VydiaRNFileUploader.m
// Vydia
//
// Created by Kenneth Leland on 12/8/16.
// Copyright © 2016 Vydia. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <MobileCoreServices/MobileCoreServices.h>
#import <React/RCTEventEmitter.h>
Expand All @@ -24,9 +16,13 @@ @implementation VydiaRNFileUploader
@synthesize bridge = _bridge;
static int uploadId = 0;
static RCTEventEmitter* staticEventEmitter = nil;
static NSString *BACKGROUND_SESSION_ID = @"VydiaRNFileUploader";
static NSString *BACKGROUND_SESSION_ID = @"ReactNativeBackgroundUpload";
NSURLSession *_urlSession = nil;

+ (BOOL)requiresMainQueueSetup {
return NO;
}

-(id) init {
self = [super init];
if (self) {
Expand Down Expand Up @@ -88,7 +84,9 @@ - (void)_sendEventWithName:(NSString *)eventName body:(id)body {
}
}

// Borrowed from http://stackoverflow.com/questions/2439020/wheres-the-iphone-mime-type-database
/*
Borrowed from http://stackoverflow.com/questions/2439020/wheres-the-iphone-mime-type-database
*/
- (NSString *)guessMIMETypeFromFileName: (NSString *)fileName {
CFStringRef UTI = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, (__bridge CFStringRef)[fileName pathExtension], NULL);
CFStringRef MIMEType = UTTypeCopyPreferredTagWithClass(UTI, kUTTagClassMIMEType);
Expand Down Expand Up @@ -149,9 +147,9 @@ - (NSString *)guessMIMETypeFromFileName: (NSString *)fileName {
[request setHTTPBody: httpBody];

// I am sorry about warning, but Upload tasks from NSData are not supported in background sessions.
uploadTask = [[self urlSession:thisUploadId] uploadTaskWithRequest:request fromData: nil];
uploadTask = [[self urlSession] uploadTaskWithRequest:request fromData: nil];
} else {
uploadTask = [[self urlSession:thisUploadId] uploadTaskWithRequest:request fromFile:[NSURL URLWithString: fileURI]];
uploadTask = [[self urlSession] uploadTaskWithRequest:request fromFile:[NSURL URLWithString: fileURI]];
}

uploadTask.taskDescription = customUploadId ? customUploadId : [NSString stringWithFormat:@"%i", thisUploadId];
Expand Down Expand Up @@ -206,10 +204,10 @@ - (NSData *)createBodyWithBoundary:(NSString *)boundary
return httpBody;
}

- (NSURLSession *)urlSession: (int) thisUploadId{
if(_urlSession == nil) {
NSURLSessionConfiguration *sessionConfigurationt = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:BACKGROUND_SESSION_ID];
_urlSession = [NSURLSession sessionWithConfiguration:sessionConfigurationt delegate:self delegateQueue:nil];
- (NSURLSession *)urlSession {
if (_urlSession == nil) {
NSURLSessionConfiguration *sessionConfiguration = [NSURLSessionConfiguration backgroundSessionConfigurationWithIdentifier:BACKGROUND_SESSION_ID];
_urlSession = [NSURLSession sessionWithConfiguration:sessionConfiguration delegate:self delegateQueue:nil];
}
return _urlSession;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-background-upload",
"version": "4.1.0",
"version": "4.2.0",
"description": "Cross platform http post file uploader with android and iOS background support",
"main": "index.js",
"scripts": {
Expand Down

0 comments on commit 6fbc204

Please sign in to comment.