Skip to content
wkh237 edited this page Jul 8, 2016 · 39 revisions

Could not send any HTTP request except localhost (IOS)

reference from official document

App Transport Security is a security feature, added in iOS 9, that rejects all HTTP requests that are not sent over HTTPS. This can result in HTTP traffic being blocked, including the developer React Native server.

ATS is disabled by default in projects generated using the React Native CLI in order to make development easier. You should re-enable ATS prior to building your app for production by removing the NSAllowsArbitraryLoads entry from your Info.plist file in the ios/ folder.

To learn more about how to configure ATS on your own Xcode projects, see this post on ATS.

Could not compile on IOS

If you're having problem when compiling IOS project, and the error looks like

ARC forbids synthesizing a property of an Objective-C ..

You should try to upgrade Xcode to version >= 7.3 or upgrade react-native-fetch-blob to latest version, because we have already solved this problem.

see also #31

Work in Progress 0.6.2

The following content are still in progress, these functions are not available in any release

How to access files from assets

After 0.6.2 you can access files inside app bundle by simply adding the prefix bundle-assets:// before the filename. You can also wrap the filename by fs.asset API. For example, upload a file from assets

let assetPath = RNFetchBlob.fs.asset('my-asset.png')
RNFetchBlob
    .fetch('POST', 'http://myupload.com/upload', 
           { 'Content-Type' : 'application/octet-stream' },
           RNFetchBlob.wrap(assetPath))
    .then((resp) => { ... })

Generally you can access the file as usual once you wrap the file name by fs.addAssetPrefix, but keep in mind, assets files are readonly, so you are not be able to remove, or change them.

Access files in CameraRoll (IOS)

Files in CameraRoll is slightly different from normal files, so it has the following restrictions.

First, you can't pass its path (something looks like assets-library://...) directly into fetch API's body, that won't work. But you can use readFile or readStream making a copy of its content, then put the content into body. The following example comes from our unit test

CameraRoll.getPhotos({first : 10})
  .then((resp) => {
    let url = resp.edges[0].node.image.uri
    return fs.readFile(url, 'base64')
  })
  .then((data) => {
    return RNFetchBlob.fetch('POST', 'https://content.dropboxapi.com/2/files/upload', {
      Authorization : `Bearer ${DROPBOX_TOKEN}`,
      'Dropbox-API-Arg': '{\"path\": \"/rn-upload/image-from-camera-roll.jpg\",\"mode\": \"add\",\"autorename\": true,\"mute\": false}',
      'Content-Type' : 'application/octet-stream',
    }, data)
  })
  .then((resp) => {
    resp = resp.json()
    report(
      <Assert key="confirm the file has been uploaded" expect={'image-from-camera-roll.jpg'} actual={resp.name}/>
    )
    done()
  })
Clone this wiki locally