Skip to content

react-native-dev/react-native-networking

 
 

Repository files navigation

react-native-networking

A react-native module to download and upload files with AFNetworking.

Pre-requisites

You should have pod installed.

$ sudo gem install cocoapods
$ pod setup

Install

  1. Open Terminal and cd to your project folder.

  2. Install react-native-networking with npm and AFNetworking with pod:

npm install react-native-networking --save && cd node_modules/react-native-networking && pod install

  1. Add and link libraries

  2. In XCode, in the project navigator, right click LibrariesAdd Files to [your project's name]

  3. Go to node_modulesreact-native-networking and add RNNetworkingManager.xcodeproj

  4. In XCode, in the project navigator, select your project. Add libRNNetworkingManager.a to your project's Build PhasesLink Binary With Libraries

  5. Click RNNetworkingManager.xcodeproj in the project navigator and go the Build Settings tab. Make sure 'All' is toggled on (instead of 'Basic'). Look for Header Search Paths and make sure it contains both $(SRCROOT)/../react-native/React and $(SRCROOT)/../../React - mark both as recursive.

  6. Run your project (Cmd+R)

Usage

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.

About

react-native module to download and upload files with AFNetworking

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Objective-C 96.1%
  • JavaScript 2.2%
  • Ruby 1.7%