Removed dir enums, updated readme

This commit is contained in:
Chris Dell 2015-10-23 00:13:12 +01:00
parent 00d312ed3f
commit 354a218573
4 changed files with 17 additions and 19 deletions

1
.gitignore vendored
View File

@ -21,3 +21,4 @@ DerivedData
.idea/ .idea/
# Pods - for those of you who use CocoaPods # Pods - for those of you who use CocoaPods
Pods Pods
update-test.sh

View File

@ -134,9 +134,7 @@ var RNFS = {
.catch(convertError); .catch(convertError);
}, },
MainBundle: RNFSManager.MainBundleDirectory, MainBundlePath: RNFSManager.MainBundlePath,
CachesDirectory: RNFSManager.NSCachesDirectory,
DocumentDirectory: RNFSManager.NSDocumentDirectory,
CachesDirectoryPath: RNFSManager.NSCachesDirectoryPath, CachesDirectoryPath: RNFSManager.NSCachesDirectoryPath,
DocumentDirectoryPath: RNFSManager.NSDocumentDirectoryPath DocumentDirectoryPath: RNFSManager.NSDocumentDirectoryPath
}; };

View File

@ -89,7 +89,7 @@ public class MainActivity extends Activity implements DefaultHardwareBackBtnHand
var RNFS = require('react-native-fs'); var RNFS = require('react-native-fs');
// get a list of files and directories in the main bundle // get a list of files and directories in the main bundle
RNFS.readDir('/', RNFS.MainBundle) RNFS.readDir(RNFS.MainBundlePath)
.then((result) => { .then((result) => {
console.log('GOT RESULT', result); console.log('GOT RESULT', result);
@ -157,10 +157,7 @@ return RNFS.unlink(path)
The following constants are available on the `RNFS` export: The following constants are available on the `RNFS` export:
`MainBundle` (`Number`) The identifier for the main bundle `MainBundlePath` (`String`) The absolute path to the main bundle directory
`CachesDirectory` (`Number`) The identifier for the caches directory
`DocumentDirectory` (`Number`) The identifier for the document directory
`CachesDirectoryPath` (`String`) The absolute path to the caches directory `CachesDirectoryPath` (`String`) The absolute path to the caches directory
`DocumentDirectoryPath` (`String`) The absolute path to the document directory `DocumentDirectoryPath` (`String`) The absolute path to the document directory

View File

@ -12,8 +12,6 @@
@implementation RNFSManager @implementation RNFSManager
static int MainBundleDirectory = 999;
RCT_EXPORT_MODULE(); RCT_EXPORT_MODULE();
- (dispatch_queue_t)methodQueue - (dispatch_queue_t)methodQueue
@ -144,13 +142,19 @@ RCT_EXPORT_METHOD(downloadFile:(NSString *)urlStr
filepath:(NSString *)filepath filepath:(NSString *)filepath
callback:(RCTResponseSenderBlock)callback) callback:(RCTResponseSenderBlock)callback)
{ {
NSError *error = nil;
NSURL *url = [NSURL URLWithString:urlStr]; NSURL *url = [NSURL URLWithString:urlStr];
NSData *urlData = [NSData dataWithContentsOfURL:url]; NSData *urlData = [NSData dataWithContentsOfURL:url options:NSDataReadingUncached error:&error];
BOOL success = NO; if (error) {
return callback([self makeErrorPayload:error]);
}
if (urlData) { BOOL success = [urlData writeToFile:filepath atomically:YES];
success = [urlData writeToFile:filepath atomically:YES];
if (!success) {
return callback(@[[NSString stringWithFormat:@"Could not write downloaded data to file at path %@", filepath]]);
} }
callback(@[[NSNull null], [NSNumber numberWithBool:success], filepath]); callback(@[[NSNull null], [NSNumber numberWithBool:success], filepath]);
@ -203,11 +207,9 @@ RCT_EXPORT_METHOD(pathForBundle:(NSString *)bundleNamed
- (NSDictionary *)constantsToExport - (NSDictionary *)constantsToExport
{ {
return @{ return @{
@"MainBundlePath": [[NSBundle mainBundle] bundlePath],
@"NSCachesDirectoryPath": [self getPathForDirectory:NSCachesDirectory], @"NSCachesDirectoryPath": [self getPathForDirectory:NSCachesDirectory],
@"NSDocumentDirectoryPath": [self getPathForDirectory:NSDocumentDirectory], @"NSDocumentDirectoryPath": [self getPathForDirectory:NSDocumentDirectory],
@"NSCachesDirectory": [NSNumber numberWithInteger:NSCachesDirectory],
@"NSDocumentDirectory": [NSNumber numberWithInteger:NSDocumentDirectory],
@"MainBundleDirectory": [NSNumber numberWithInteger:MainBundleDirectory],
@"NSFileTypeRegular": NSFileTypeRegular, @"NSFileTypeRegular": NSFileTypeRegular,
@"NSFileTypeDirectory": NSFileTypeDirectory @"NSFileTypeDirectory": NSFileTypeDirectory
}; };