1

I'm working on a swift app that contains a UIWebView and the site that it shows is kinda big and it has a lot of pictures and javascript, when I test it on a virtual device, it works. but on a real Iphone or Ipad it crashes after a couple of seconds, Xcode shows me the memory usage goes around 50 mb and the cpu usage goes up until 101% and the app crashes.

Is there a way to fix this without editing the website?

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Sophie Bernard
  • 197
  • 3
  • 13
  • Probably not. If your website is loaded with JS, I bet this is causing your memory leap. – GIJOW Jul 26 '17 at 17:39
  • Check your webview delegate methods. `webViewDidLoad` should be called constantly. Share you code you've tried. – Krunal Jul 26 '17 at 17:53
  • GIJOW.. yup the site's content uses JS, but how come? a huge company like apple can't make a web view that handles JS smoothly? – Sophie Bernard Jul 26 '17 at 17:59
  • Krunal.. I didn't use webViewDidLoad at all, this is the code that contains the web view var ViewURL = URL(string: "example.com") and in the view did load: let ViewURLRequest = URLRequest (url: ViewURL!) webView.loadRequest(ViewURLRequest) – Sophie Bernard Jul 26 '17 at 18:02
  • Have you tried viewing the website in Safari on an iPhone or iPad? – paulvs Jul 26 '17 at 18:02
  • @paulvs .. Yes I did, and It works fine on safari – Sophie Bernard Jul 26 '17 at 18:05
  • Is it possible for you to share the URL? – paulvs Jul 26 '17 at 18:06
  • 1
    here's the website's link in case anyone wants to test http://doctor-store.com/ – Sophie Bernard Jul 26 '17 at 18:08
  • [`UIWebView` != mobile Safari](https://stackoverflow.com/questions/11648184/uiwebview-and-safari-comparison). If you are targeting iOS 8 and later, `WKWebView` will offer much better Javascript performance. The only annoyance is that you can't drag a `WKWebView` into your storyboard in Interface Builder but this has been fixed as of Xcode 9 Beta 4 – Code Different Jul 26 '17 at 20:02
  • I agree with Code Different. You will probably be happier once you start using WKWebview rather than UIWebView. It's easy to add it via code, so don't let that stop you. – Mozahler Jul 26 '17 at 22:59

0 Answers0