Unable to load game locally in WKWebview on iOS.

0 favourites
  • 5 posts
From the Asset Store
Shark.io
$49 USD
Shark.io in the sea full of killer sharks, Sunday of life is the game. Who knows what is happening under the sea?
  • Hello,

    Im trying to load an exported game into my WKWebview without any success. Im trying to load the game locally from disk. I am able to do this with a game exported from ctjs so far.

    Heres what I am doing.

    1. game is stored as a zip on my server

    2. app downloads zip and unzips to users document directory

    3. I then launch the try launching the game from the directory

    Heres what the setup looks like.

    Directory of the upzipped game on the phone looks like this:

    file:///var/mobile/Containers/Data/Application/37C0D30F-415E-4CF8-8177-FCA0CD3566BD/Documents/6CtBOiFP0ieN4GVQKhQp/

    Files are at the root like: index.html, data.json, etc

    I open my WKWebview these settings:

    let configs = WKWebViewConfiguration() configs.setValue(true, forKey: "_allowUniversalAccessFromFileURLs") <-- needed for serving locally let webView = WKWebView(frame: .zero, configuration: configs) context.coordinator.parent = webView //.... Task { let url = await game.downloadZipFile() let index = url?.appendingPathComponent("index.html") if let dir = url, let index = index { webView.loadFileURL(index, allowingReadAccessTo: dir) <-- needed for serving locally } }

    Again, I can do this with an exported ctjs game and it loads as expected. But when I try to load the example game Glokar in this manner I get the following error.

    Now, I've tried this with the HTML5 export. Also, I've tried with the macos export, grabbed the contents of the www folder and also added the usercontentcontroller message handlers for 'C3Wrapper', but still the same error. I do get the messagehandler called with {"type":"ready"}.

    Heres screen shots of the promise not handled rejection. Any ideas? :)

    Tagged:

  • You can't load projects over the file: protocol. So many things get blocked for security reasons it won't load at all. There are quite a few significant changes that need to be made to get it to load.

    Why not use the built-in iOS export? That loads the game in WKWebView and handles all of this for you.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • You can't load projects over the file: protocol. So many things get blocked for security reasons it won't load at all. There are quite a few significant changes that need to be made to get it to load.

    Why not use the built-in iOS export? That loads the game in WKWebView and handles all of this for you.

    Hey Ashley,

    Thanks for the reply! So what Im building is a mini game app of sorts. The games part of it is only about 50% of the app. The app is written in SwiftUI and for each game I open up a custom WKWebview which launches each mini game. I was trying to avoid having to host/serve each of the games. My hope was to simply have zip files of each of the games that I could download and run locally. My custom WKWebview also has message handlers to bridge some custom functionality to and from the mini games.

    I tried using the macos export and pulling out the contents of the www folder, but as mentioned above Im not sure if I need to call something from the wkwebview side to initiate the game. I also havent tried pulling from the iOS export. I will do that next.

    Im curious though, you mentioned not supporting the file:// protocol, but isnt the macos * ios exports utilizing that?

    At anyrate, I hope this explains better what Im trying to do.

  • My hope was to simply have zip files of each of the games that I could download and run locally.

    Construct games work offline once they've loaded. So serving from HTTPS doesn't sound all that different to just downloading and loading zips. So maybe you could just use a server after all?

    Im curious though, you mentioned not supporting the file:// protocol, but isnt the macos * ios exports utilizing that?

    Not any more - we moved to an app: scheme using WKURLSchemeHandler a couple of years ago to get off the restrictions of the file: protocol. Even before that, we had tons of ugly compatibility code in Cordova mode to handle all the problems of running on file:.

  • Yeah, I guess I could just host them. Probably making more work for myself than needed anyways.

    FYI, just wanted to mention that construct is great! Been programming for 10 years, but every time I hop into construct its really refreshing how easy it is to put together a game. :)

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)