A react-native module to download and upload files with AFNetworking.
You should have pod installed.
$ sudo gem install cocoapods
$ pod setup
-
Open Terminal and
cdto your project folder. -
Install react-native-networking with npm and AFNetworking with pod:
npm install react-native-networking --save && cd node_modules/react-native-networking && pod install
-
Add and link libraries
-
In XCode, in the project navigator, right click
Libraries➜Add Files to [your project's name] -
Go to
node_modules➜react-native-networkingand addRNNetworkingManager.xcodeproj -
In XCode, in the project navigator, select your project. Add
libRNNetworkingManager.ato your project'sBuild Phases➜Link Binary With Libraries -
Click
RNNetworkingManager.xcodeprojin the project navigator and go theBuild Settingstab. Make sure 'All' is toggled on (instead of 'Basic'). Look forHeader Search Pathsand make sure it contains both$(SRCROOT)/../react-native/Reactand$(SRCROOT)/../../React- mark both asrecursive. -
Run your project (
Cmd+R)
In your react-native project, require the module:
var RNNetworkingManager = require('react-native-networking');
var url = 'localhost:3000';
// Example GET request, (download)
RNNetworkingManager.requestFile(url, {
'method':'GET'
}, function(results) {
console.log(results);
});
// Example POST request, (upload)
RNNetworkingManager.requestFile(url, {
'method': 'POST',
'data' : 'pathToYourFileHere'
}, function(results) {
console.log(results);
});The GET request automatically downloads the file to the Documents/ in your app. Similarly, the POST request automatically uploads from Documents/ of your app.
Please feel free to open issues and contribute.