9

I have a toy iOS app that's just for me. It's a native wrapper of a web-based WebAssembly-heavy game.

It's one of those where you set a task, and then wait for it to complete. Great for desktop browsers where you can just leave an open window in the corner of the display and work elsewhere.

WKWebView, however, seems to go inactive and stops processing game content when the app is backgrounded. I'd like any way (evil hacks accepted) to keep this from happening, so that the game does not pause or go inactive.

I've tried a number of hacks, including:

  • attaching the web view to the key window (deprecated in iOS 13 beta)
  • using an audio session to keep the app alive in the background
  • pumping the web view with evaluateJavaScript calls on a timer while in the background

...to no avail. Any solutions welcome!

(p.s., I'm aware of a couple other questions like this one, but want to ask my own to manage the bounty and also I'm not sure if the game being WASM makes a difference, vs. the other questions specifically calling out JavaScript)

MikeyWard
  • 1,123
  • 9
  • 19
  • 2
    Having the same issue with background audio from WkWebView in iOS 13. When going into background, audio stops even if enabled in Background Modes. – Marco Martignone Aug 16 '19 at 14:11
  • 1
    I think this should work for you? https://github.com/ionic-team/cordova-plugin-ionic-webview/blob/cb1f0266f6c3c37efae6c9a66bfca3d49884fdb6/src/ios/CDVWKWebViewEngine.m#L170. I don't have iOS to test but this looks promising and tested in cordova – Tarun Lalwani Aug 17 '19 at 16:37
  • hey, would actually evaluation on the device be only available option for you? Maybe I'm talking bullshit, but in theory you could run ur game on behalf of the device user at https://cloud.google.com/nodejs/ ... so, only fetching update after app becomes active... If device only → it's probably a bad hack, and we have to wonder through jailbreak. Or look for iOS bugs :) – Oleg Shanyuk Aug 19 '19 at 09:58
  • Not sure, but I hope this link helps, check the accepted answer: https://stackoverflow.com/questions/26514090/wkwebview-does-not-run-javascriptxml-http-request-with-out-adding-a-parent-vie – Prashant Aug 20 '19 at 12:56
  • Have you tried this option? [WKWebview does not run javascript(XML HTTP request) without adding a parent view](https://stackoverflow.com/a/40739474/7981701). If you minimize the application, you can save the state the next time you open it and restore the state. – Alexander Jul 07 '20 at 10:04

0 Answers0