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

Fix Xcode and Java deprecation warnings #752

Merged
merged 7 commits into from
Oct 19, 2019
Merged
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
2 changes: 1 addition & 1 deletion Downloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ typedef void (^DownloadCompleteCallback)(NSNumber*, NSNumber*);
typedef void (^ErrorCallback)(NSError*);
typedef void (^BeginCallback)(NSNumber*, NSNumber*, NSDictionary*);
typedef void (^ProgressCallback)(NSNumber*, NSNumber*);
typedef void (^ResumableCallback)();
typedef void (^ResumableCallback)(void);

@interface RNFSDownloadParams : NSObject

Expand Down
8 changes: 4 additions & 4 deletions Downloader.m
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ - (void)URLSession:(NSURLSession *)session downloadTask:(NSURLSessionDownloadTas
NSNumber* progress = [NSNumber numberWithUnsignedInt: floor(doublePercents)];
if ([progress unsignedIntValue] % [_params.progressDivider integerValue] == 0) {
if (([progress unsignedIntValue] != [_lastProgressValue unsignedIntValue]) || ([_bytesWritten unsignedIntegerValue] == [_contentLength longValue])) {
NSLog(@"---Progress callback EMIT--- %zu", [progress unsignedIntValue]);
NSLog(@"---Progress callback EMIT--- %u", [progress unsignedIntValue]);
_lastProgressValue = [NSNumber numberWithUnsignedInt:[progress unsignedIntValue]];
return _params.progressCallback(_contentLength, _bytesWritten);
}
Expand Down Expand Up @@ -140,15 +140,15 @@ - (void)stopDownload
[_task cancelByProducingResumeData:^(NSData * _Nullable resumeData) {
if (resumeData != nil) {
self.resumeData = resumeData;
_params.resumableCallback();
self->_params.resumableCallback();
} else {
NSError *error = [NSError errorWithDomain:@"RNFS"
code:@"Aborted"
code:0 //used to pass an NSString @"Aborted" here, but it needs an NSInteger
userInfo:@{
NSLocalizedDescriptionKey: @"Download has been aborted"
}];

_params.errorCallback(error);
self->_params.errorCallback(error);
}
}];

Expand Down
20 changes: 11 additions & 9 deletions FS.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@

var RNFSManager = require('react-native').NativeModules.RNFSManager;

var NativeAppEventEmitter = require('react-native').NativeAppEventEmitter; // iOS
var DeviceEventEmitter = require('react-native').DeviceEventEmitter; // Android
var NativeEventEmitter = require('react-native').NativeEventEmitter;

var RNFS_NativeEventEmitter = new NativeEventEmitter(RNFSManager);

var base64 = require('base-64');
var utf8 = require('utf8');
var isIOS = require('react-native').Platform.OS === 'ios';
Expand Down Expand Up @@ -494,15 +496,15 @@ var RNFS = {
var subscriptions = [];

if (options.begin) {
subscriptions.push(NativeAppEventEmitter.addListener('DownloadBegin-' + jobId, options.begin));
subscriptions.push(RNFS_NativeEventEmitter.addListener('DownloadBegin', options.begin));
}

if (options.progress) {
subscriptions.push(NativeAppEventEmitter.addListener('DownloadProgress-' + jobId, options.progress));
subscriptions.push(RNFS_NativeEventEmitter.addListener('DownloadProgress', options.progress));
}

if (options.resumable) {
subscriptions.push(NativeAppEventEmitter.addListener('DownloadResumable-' + jobId, options.resumable));
subscriptions.push(RNFS_NativeEventEmitter.addListener('DownloadResumable', options.resumable));
}

var bridgeOptions = {
Expand Down Expand Up @@ -547,19 +549,19 @@ var RNFS = {
if (options.method && typeof options.method !== 'string') throw new Error('uploadFiles: Invalid value for property `method`');

if (options.begin) {
subscriptions.push(NativeAppEventEmitter.addListener('UploadBegin-' + jobId, options.begin));
subscriptions.push(RNFS_NativeEventEmitter.addListener('UploadBegin', options.begin));
}
if (options.beginCallback && options.beginCallback instanceof Function) {
// Deprecated
subscriptions.push(NativeAppEventEmitter.addListener('UploadBegin-' + jobId, options.beginCallback));
subscriptions.push(RNFS_NativeEventEmitter.addListener('UploadBegin', options.beginCallback));
}

if (options.progress) {
subscriptions.push(NativeAppEventEmitter.addListener('UploadProgress-' + jobId, options.progress));
subscriptions.push(RNFS_NativeEventEmitter.addListener('UploadProgress', options.progress));
}
if (options.progressCallback && options.progressCallback instanceof Function) {
// Deprecated
subscriptions.push(NativeAppEventEmitter.addListener('UploadProgress-' + jobId, options.progressCallback));
subscriptions.push(RNFS_NativeEventEmitter.addListener('UploadProgress', options.progressCallback));
}

var bridgeOptions = {
Expand Down
4 changes: 2 additions & 2 deletions IntegrationTests/IntegrationTests.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -553,7 +553,7 @@
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../React/**",
);
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -593,7 +593,7 @@
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/include,
"$(SRCROOT)/../React/**",
);
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
Expand Down
2 changes: 1 addition & 1 deletion RNFS.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Pod::Spec.new do |s|
s.license = pjson["license"]
s.author = { "Johannes Lumpe" => "johannes@lum.pe" }

s.ios.deployment_target = '7.0'
s.ios.deployment_target = '8.0'
s.tvos.deployment_target = '9.2'

s.source = { :git => "https://github.com/itinance/react-native-fs", :tag => "v#{s.version}" }
Expand Down
4 changes: 2 additions & 2 deletions RNFS.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -261,7 +261,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = YES;
ONLY_ACTIVE_ARCH = YES;
SDKROOT = iphoneos;
Expand Down Expand Up @@ -297,7 +297,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
IPHONEOS_DEPLOYMENT_TARGET = 7.0;
IPHONEOS_DEPLOYMENT_TARGET = 8.0;
MTL_ENABLE_DEBUG_INFO = NO;
SDKROOT = iphoneos;
VALIDATE_PRODUCT = YES;
Expand Down
5 changes: 3 additions & 2 deletions RNFSManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@
//

#import <React/RCTBridgeModule.h>
#import <React/RCTEventEmitter.h>
#import <React/RCTLog.h>

typedef void (^CompletionHandler)();
typedef void (^CompletionHandler)(void);

@interface RNFSManager : NSObject <RCTBridgeModule>
@interface RNFSManager : RCTEventEmitter <RCTBridgeModule>

+(void)setCompletionHandlerForIdentifier: (NSString *)identifier completionHandler: (CompletionHandler)completionHandler;

Expand Down
43 changes: 29 additions & 14 deletions RNFSManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ @implementation RNFSManager

static NSMutableDictionary *completionHandlers;

@synthesize bridge = _bridge;

RCT_EXPORT_MODULE();

- (dispatch_queue_t)methodQueue
Expand Down Expand Up @@ -157,8 +155,15 @@ + (BOOL)requiresMainQueueSetup
[fH writeData:data];

return resolve(nil);
} @catch (NSException *e) {
return [self reject:reject withError:e];
} @catch (NSException *exception) {
NSMutableDictionary * info = [NSMutableDictionary dictionary];
[info setValue:exception.name forKey:@"ExceptionName"];
[info setValue:exception.reason forKey:@"ExceptionReason"];
[info setValue:exception.callStackReturnAddresses forKey:@"ExceptionCallStackReturnAddresses"];
[info setValue:exception.callStackSymbols forKey:@"ExceptionCallStackSymbols"];
[info setValue:exception.userInfo forKey:@"ExceptionUserInfo"];
NSError *err = [NSError errorWithDomain:@"RNFS" code:0 userInfo:info];
return [self reject:reject withError:err];
}
}

Expand Down Expand Up @@ -452,6 +457,11 @@ + (BOOL)requiresMainQueueSetup
resolve(nil);
}

- (NSArray<NSString *> *)supportedEvents
{
return @[@"UploadBegin",@"UploadProgress",@"DownloadBegin",@"DownloadProgress",@"DownloadResumable"];
}

RCT_EXPORT_METHOD(downloadFile:(NSDictionary *)options
resolver:(RCTPromiseResolveBlock)resolve
rejecter:(RCTPromiseRejectBlock)reject)
Expand Down Expand Up @@ -501,22 +511,24 @@ + (BOOL)requiresMainQueueSetup
};

params.beginCallback = ^(NSNumber* statusCode, NSNumber* contentLength, NSDictionary* headers) {
[self.bridge.eventDispatcher sendAppEventWithName:[NSString stringWithFormat:@"DownloadBegin-%@", jobId]
body:@{@"jobId": jobId,
@"statusCode": statusCode,
@"contentLength": contentLength,
@"headers": headers ?: [NSNull null]}];
if (self.bridge != nil)
[self sendEventWithName:@"DownloadBegin" body:@{@"jobId": jobId,
@"statusCode": statusCode,
@"contentLength": contentLength,
@"headers": headers ?: [NSNull null]}];
};

params.progressCallback = ^(NSNumber* contentLength, NSNumber* bytesWritten) {
[self.bridge.eventDispatcher sendAppEventWithName:[NSString stringWithFormat:@"DownloadProgress-%@", jobId]
if (self.bridge != nil)
[self sendEventWithName:@"DownloadProgress"
body:@{@"jobId": jobId,
@"contentLength": contentLength,
@"bytesWritten": bytesWritten}];
};

params.resumableCallback = ^() {
[self.bridge.eventDispatcher sendAppEventWithName:[NSString stringWithFormat:@"DownloadResumable-%@", jobId] body:nil];
if (self.bridge != nil)
[self sendEventWithName:@"DownloadResumable" body:nil];
};

if (!self.downloaders) self.downloaders = [[NSMutableDictionary alloc] init];
Expand Down Expand Up @@ -614,12 +626,14 @@ + (BOOL)requiresMainQueueSetup
};

params.beginCallback = ^() {
[self.bridge.eventDispatcher sendAppEventWithName:[NSString stringWithFormat:@"UploadBegin-%@", jobId]
if (self.bridge != nil)
[self sendEventWithName:@"UploadBegin"
body:@{@"jobId": jobId}];
};

params.progressCallback = ^(NSNumber* totalBytesExpectedToSend, NSNumber* totalBytesSent) {
[self.bridge.eventDispatcher sendAppEventWithName:[NSString stringWithFormat:@"UploadProgress-%@", jobId]
if (self.bridge != nil)
[self sendEventWithName:@"UploadProgress"
body:@{@"jobId": jobId,
@"totalBytesExpectedToSend": totalBytesExpectedToSend,
@"totalBytesSent": totalBytesSent}];
Expand Down Expand Up @@ -808,7 +822,8 @@ + (BOOL)requiresMainQueueSetup
rejecter: (RCTPromiseRejectBlock) reject)
{
NSURL* url = [NSURL URLWithString:imageUri];
__block NSURL* videoURL = [NSURL URLWithString:destination];
//unused?
//__block NSURL* videoURL = [NSURL URLWithString:destination];
__block NSError *error = nil;

PHFetchResult *phAssetFetchResult = [PHAsset fetchAssetsWithALAssetURLs:@[url] options:nil];
Expand Down
2 changes: 1 addition & 1 deletion Uploader.m
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ - (void)uploadFiles:(RNFSUploadParams*)params
NSURLSession *session = [NSURLSession sessionWithConfiguration:sessionConfiguration delegate:(id)self delegateQueue:[NSOperationQueue mainQueue]];
_task = [session dataTaskWithRequest:req completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSString * str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
return _params.completeCallback(str, response);
return self->_params.completeCallback(str, response);
}];
[_task resume];
_params.beginCallback();
Expand Down
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ android {
buildToolsVersion safeExtGet('buildToolsVersion', '26.0.3')

defaultConfig {
minSdkVersion safeExtGet('minSdkVersion', 16)
minSdkVersion safeExtGet('minSdkVersion', 19)
targetSdkVersion safeExtGet('targetSdkVersion', 26)
versionCode 1
versionName "1.0"
Expand Down
6 changes: 1 addition & 5 deletions android/src/main/java/com/rnfs/Downloader.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
package com.rnfs;

import java.io.File;
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.BufferedInputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.IOException;
import java.net.URL;
import java.net.URLConnection;
import java.net.HttpURLConnection;
import java.util.*;
import java.util.concurrent.atomic.AtomicBoolean;
Expand Down Expand Up @@ -90,7 +86,7 @@ private void download(DownloadParams param, DownloadResult res) throws Exception
if(statusCode >= 200 && statusCode < 300) {
Map<String, List<String>> headers = connection.getHeaderFields();

Map<String, String> headersFlat = new HashMap<String, String>();
Map<String, String> headersFlat = new HashMap<>();

for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
String headerKey = entry.getKey();
Expand Down
20 changes: 10 additions & 10 deletions android/src/main/java/com/rnfs/RNFSManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import android.util.Base64;
import android.util.SparseArray;
import android.media.MediaScannerConnection;
import android.net.Uri;

import com.facebook.react.bridge.Arguments;
import com.facebook.react.bridge.Promise;
Expand Down Expand Up @@ -57,8 +56,8 @@ public class RNFSManager extends ReactContextBaseJavaModule {
private static final String RNFSFileTypeRegular = "RNFSFileTypeRegular";
private static final String RNFSFileTypeDirectory = "RNFSFileTypeDirectory";

private SparseArray<Downloader> downloaders = new SparseArray<Downloader>();
private SparseArray<Uploader> uploaders = new SparseArray<Uploader>();
private SparseArray<Downloader> downloaders = new SparseArray<>();
private SparseArray<Uploader> uploaders = new SparseArray<>();

private ReactApplicationContext reactContext;

Expand All @@ -69,7 +68,7 @@ public RNFSManager(ReactApplicationContext reactContext) {

@Override
public String getName() {
return this.MODULE_NAME;
return MODULE_NAME;
}

private Uri getFileUri(String filepath, boolean isDirectoryAllowed) throws IORejectionException {
Expand All @@ -94,6 +93,7 @@ private String getOriginalFilepath(String filepath, boolean isDirectoryAllowed)
if (cursor.moveToFirst()) {
originalFilepath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
}
cursor.close();
} catch (IllegalArgumentException ignored) {
}
}
Expand Down Expand Up @@ -288,7 +288,7 @@ public void readFileRes(String filename, Promise promise) {
byte[] buffer = new byte[stream.available()];
stream.read(buffer);
String base64Content = Base64.encodeToString(buffer, Base64.NO_WRAP);
promise.resolve(base64Content);;
promise.resolve(base64Content);
} catch (Exception ex) {
ex.printStackTrace();
reject(promise, filename, ex);
Expand Down Expand Up @@ -476,7 +476,7 @@ public void readDirAssets(String directory, Promise promise) {
}
} catch (IOException ex) {
//.. ah.. is a directory or a compressed file?
isDirectory = ex.getMessage().indexOf("compressed") == -1;
isDirectory = !ex.getMessage().contains("compressed");
}
fileMap.putInt("size", length);
fileMap.putInt("type", isDirectory ? 1 : 0); // if 0, probably a folder..
Expand Down Expand Up @@ -742,7 +742,7 @@ public void onDownloadBegin(int statusCode, long contentLength, Map<String, Stri
data.putDouble("contentLength", (double)contentLength);
data.putMap("headers", headersMap);

sendEvent(getReactApplicationContext(), "DownloadBegin-" + jobId, data);
sendEvent(getReactApplicationContext(), "DownloadBegin", data);
}
};

Expand All @@ -754,7 +754,7 @@ public void onDownloadProgress(long contentLength, long bytesWritten) {
data.putDouble("contentLength", (double)contentLength);
data.putDouble("bytesWritten", (double)bytesWritten);

sendEvent(getReactApplicationContext(), "DownloadProgress-" + jobId, data);
sendEvent(getReactApplicationContext(), "DownloadProgress", data);
}
};

Expand Down Expand Up @@ -821,7 +821,7 @@ public void onUploadBegin() {

data.putInt("jobId", jobId);

sendEvent(getReactApplicationContext(), "UploadBegin-" + jobId, data);
sendEvent(getReactApplicationContext(), "UploadBegin", data);
}
};

Expand All @@ -833,7 +833,7 @@ public void onUploadProgress(int totalBytesExpectedToSend,int totalBytesSent) {
data.putInt("totalBytesExpectedToSend", totalBytesExpectedToSend);
data.putInt("totalBytesSent", totalBytesSent);

sendEvent(getReactApplicationContext(), "UploadProgress-" + jobId, data);
sendEvent(getReactApplicationContext(), "UploadProgress", data);
}
};

Expand Down