1

Is there any way to create the server in android and iOS to run a web-view? I want to run a local HTML file in a web-view with a local-host URL.

I have already searched for this on the following links but could not find any solution.

GCDWebServer

local-http-server-for-ios

Supercharging the Android WebView

Hereby i am sharing the actual scenario :

1) Download ".zip" file from server and save it on application library directory for offline use.

2) ".zip" file contents html and javascript files. It works when the HTML page is simple. But if the HTML references something else, i.e. a JavaScript file also in the library directory (with an absolute path like ), it will fail to load.

3) I need to setup local server in my device, On application launch local server starts and upload the application library directory on local server and then load the content using local host. See below example

  • Using Library directory path

file:////Users/prince/Library/Developer/CoreSimulator/Devices/75EF3DD7-DFD1-4EDB-9A6B-9FBA60F4D98C/data/Containers/Data/Application/32F774B2-E811-4281-A37A-DC8A5183B7C8/Library/Application%20Support/adededfe6c1c7bd8b5d5adb19861b9e0/Responses/36b8f6a8d6f58d58f117856dc80b0d37/abc.html

  • Using localhost path

http://localhost:8080/Application%20Support/adededfe6c1c7bd8b5d5adb19861b9e0/Responses/36b8f6a8d6f58d58f117856dc80b0d37/abc.html

Does anyone know why this happens, and how to resolve the issue?

  • 3rd and 4th links are the same. please correct it. – Ganesa Vijayakumar Nov 20 '19 at 04:22
  • Do you _need_ to load the content via http? So is the protocol relevant here? Or do you just want to display your locally stored HTML file in the web view (since the latter is relatively easy by using a `URLRequest` with a file URL...)? – Lutz Nov 20 '19 at 07:38
  • We need to load the content via http local not from the local file which is already in application directory. – Prince Sojitra Nov 20 '19 at 09:20
  • What do you mean with http local? Why do you need a webserver on a phone to serve a file to a webview on the same phone? – blackapps Nov 20 '19 at 10:29
  • Yes, a webserver on a phone to serve a file to a webview on the same phone – Prince Sojitra Nov 20 '19 at 11:43
  • Does anyone know why this happens, and how to resolve the issue? @GanesaVijayakumar – Prince Sojitra Nov 21 '19 at 07:16
  • `But if the HTML references something else, i.e. a JavaScript file also in the library directory (with an absolute path like ), it will fail to load.` No. Not on Android. – blackapps Nov 21 '19 at 08:14
  • `On application launch local server starts and upload the application library directory on local server ` I have no idea what uploading an application directory would be. On local server? But you started the local server that should do this??? – blackapps Nov 21 '19 at 08:15
  • `and then load the content using local host.` WHich content has to be loaded? And your local server uses local host???? In which way? Your words are strange. – blackapps Nov 21 '19 at 08:17
  • But to keep it short: for Android have a look at NanoHTTPD webserver. – blackapps Nov 21 '19 at 08:17
  • `and then load the content using local host.` That is not an Android path. Is it from your PC? Fom iOs? – blackapps Nov 21 '19 at 08:19
  • `Using Library directory path` That is not an Android path. Is it from your PC? From iOs? – blackapps Nov 21 '19 at 08:20
  • `Using localhost path` Your webserver would use that path? Dont get it. Localhost refers to the device itself. – blackapps Nov 21 '19 at 08:21
  • and then load the content using local host. That is not an Android path. Is it from your PC? Fom iOs? ---> it's for the iOS @blackapps – Prince Sojitra Nov 21 '19 at 08:21
  • But to keep it short: for Android have a look at NanoHTTPD webserver ---> it works fine for android but what about the iOS @blackapps – Prince Sojitra Nov 21 '19 at 08:22
  • I dont know iOS. Sorry. – blackapps Nov 21 '19 at 08:23
  • But if the HTML references something else, i.e. a JavaScript file also in the library directory (with an absolute path like ), it will fail to load. No. Not on Android. -----> What about the iOS @blackapps – Prince Sojitra Nov 21 '19 at 08:24
  • `I dont know iOS. Sorry.` If you have an iOS device then a simple test would tell you. – blackapps Nov 21 '19 at 08:26
  • Have you found a solution or a workaround? – Youssef Hossam May 16 '23 at 21:08

0 Answers0