1

I tried to load UIWebView in swift so far am able to call and load webservices without any problem , both webview and json services in simulator.

But when I tried load it in device all the other webservices are working except UIWebView.

let url = "http://192.168.1.233/PhpProject1/MoreDetails.php?id=1234"


 UIWebView.loadRequest(webView)(NSURLRequest(URL: NSURL(string: url)!))

I checked the log but nothing happens after calling the UIWebView in the device.

The problem is that only webview is not loading in device, I am able to call all other webservices, and everything is working fine in emulator.

Eric Aya
  • 69,473
  • 35
  • 181
  • 253
milsha
  • 79
  • 2
  • 10
  • 1
    add delegate method for your webview & also check for the network connectivity of device. If you are working on iOS 9.x.x version device so use ATS (App transport Security) key in your plist file because your using HTTP. For more about ATS plz go https://gist.github.com/mlynch/284699d676fe9ed0abfa – Gagan_iOS Jun 07 '16 at 10:03
  • @Gagan_iOS i have already enabled app transport security , i already mentioned that all the other webservices are working fine. only problem is for webview. IN EMULATOR EVERYTHING IS LOADING FINE BUT ONLY IN DEVICE WEBVIEW DOES NOT LOAD. – milsha Jun 07 '16 at 10:13
  • are u using same url "http://192.168.1.233/PhpProject1/MoreDetails.php?id=1234". I have tried to open it in my browser & it's not getting load. In simulator I am getting time out error as 2016-06-07 15:52:37.620 Test[5796:329704] webViewDidStartLoad 2016-06-07 15:53:38.346 Test[5796:329704] Error is : The request timed out. – Gagan_iOS Jun 07 '16 at 10:25
  • @Gagan_iOS its our private IP. we are getting the result in the browser directly. – milsha Jun 07 '16 at 10:39

2 Answers2

0

192.168.1 seems a private LAN , probably reachable by your MAC PC through the wired cable (ethernet cable). If you have your iPhone connected throught WIFI probably it's not the same lan, or WIFI cannot reach the 192.168.1.x. Check your connections.

Apple provides reachability classes you can use the class to check if Reachability(hostname: <your host>) is true or not for both devices (PC and iPhone). You can also look the swift translated reachability here in gitHub, there are many examples to how to do it.

Alessandro Ornano
  • 34,887
  • 11
  • 106
  • 133
0

From ios 9 apple introduced NSAppTransportSecurity means you can't hit http server from your device. So you have to use url with https. But still you can hit http by adding exception in info.plist. For that you can see this link

How can I add NSAppTransportSecurity to my info.plist file?.

And as said by others always use reachability class to check wether the server is reachable or not :)

Community
  • 1
  • 1
iamgautam
  • 90
  • 1
  • 11