0

My idea , is to make my react native app to update , its js files form the web . on each load (only if there is an update). There is a two aproaches for that.

First one is to do it inside the v8 . Use a diffrenet require function,

myRequire(jsUrl, './offlineLocalJs.js');

myRequire implantation based on this answer.

There are two problems with this aproach

  • if myRequire is async , so each module would be written promises/callbacks
  • myRequrie is sync. so the app load time will slow down

Second Approach

Use a native IOS module that does http requests to fetch the files, and updates the bundle files, and javascript stays as is.

Some how im in favor off the second approach. but my i dont know much about ios devlopment.

I be happy to hear thoughts , about this idea , and suggestions Thanks

Community
  • 1
  • 1
doron aviguy
  • 2,554
  • 2
  • 22
  • 18
  • Write native modules for iOS and Android. A good place to start would be looking at what currently happens. Start at your AppDelegate.m. Worry about the offline case early. – jamesh Aug 09 '15 at 12:20

1 Answers1

3

Im answering my own question , i should probably ask this on react-native Github page.

I solved this issue , by changing jsCodeLocation in AppDelegate.m

//AppDelegate.m

//original line (development mode)
jsCodeLocation = [NSURL URLWithString:@"http://localhost:8081/index.ios.bundle"]; change it to 

point react native to your compiled webpack file , and upload to your server and insert the url to jsCodeLocation variable.

index.ios.bundle content is actually the content of http://localhost:8081/index.ios.bundle?dev=false&minify=true dev server compiled version

//Point RN to my complied js file  
jsCodeLocation = [NSURL URLWithString:@"http://s3-bucket.com/index.ios.bundle.js"];

One thing Im missing in this solution , is the network check. In case there is no internet available i should fallback to static/default version.

This solution gives , the me ability , to auto update my app by uploading a new js bundle.

I can even add more npm modules , as long as they are pure js (no binaries).

doron aviguy
  • 2,554
  • 2
  • 22
  • 18