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/
# Pods - for those of you who use CocoaPods
Pods
update-test.sh

View File

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

View File

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

View File

@ -12,8 +12,6 @@
@implementation RNFSManager
static int MainBundleDirectory = 999;
RCT_EXPORT_MODULE();
- (dispatch_queue_t)methodQueue
@ -144,13 +142,19 @@ RCT_EXPORT_METHOD(downloadFile:(NSString *)urlStr
filepath:(NSString *)filepath
callback:(RCTResponseSenderBlock)callback)
{
NSError *error = nil;
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) {
success = [urlData writeToFile:filepath atomically:YES];
BOOL 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]);
@ -203,11 +207,9 @@ RCT_EXPORT_METHOD(pathForBundle:(NSString *)bundleNamed
- (NSDictionary *)constantsToExport
{
return @{
@"MainBundlePath": [[NSBundle mainBundle] bundlePath],
@"NSCachesDirectoryPath": [self getPathForDirectory:NSCachesDirectory],
@"NSDocumentDirectoryPath": [self getPathForDirectory:NSDocumentDirectory],
@"NSCachesDirectory": [NSNumber numberWithInteger:NSCachesDirectory],
@"NSDocumentDirectory": [NSNumber numberWithInteger:NSDocumentDirectory],
@"MainBundleDirectory": [NSNumber numberWithInteger:MainBundleDirectory],
@"NSFileTypeRegular": NSFileTypeRegular,
@"NSFileTypeDirectory": NSFileTypeDirectory
};