Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
TagsGame Engines
(1 edit) (+1)

After a bit more research I have an answer. Basically, on itch and iOS, you cannot save to the browser and have it extend beyond the current session. The iframe and the page itself are two different domains, so its a CORS problem. The solution would be a server that users make an account/sign into, which is not ideal for quicker/more arcadey titles. For websites other than itch, there is hope for webgl games saving on iOS. If you own the page itself as well as the webgl, you can communicate from the iframe to the page to post data, this method uses window.postMessage which you can read up on here: https://www.teamsimmer.com/2023/05/02/how-do-i-use-the-postmessage-method-with-c...

So other than itch decided to give us access to our pages JS, we're out of luck. I also considered using cookies but we're limited to 4096ish bytes and I don't even know if we can do that from the iframe. Honestly I saw that the size was that small and figured it wasn't worth it.

I guess the best solution would be to throw your game up on a little site so you can handle saving to browser, then include a link to that page on the itch and hope mobile players find it? Or make a real iOS build and put it on the appstore. Neither solution works well for quicker/shorter titles.

Just before posting I found this post (https://itch.io/t/635029/enable-a-way-for-browser-games-to-access-the-username-o...) where someone asked Leafo the founder of itch if he would consider adding support for window.postMessage, it looks like a no but he was open to extending the current JS API. Maybe with our powers combined we can summon him here and get a mobile specific JS way to read/write to indexedDB/localStorage.

(+1)

In my workaround I split my savefile into several cookies. This allows you to bypass the memory limit.
But of course that's not a nice solution either.

Ah nice, any idea if that works for iOS/iFrames?

Never tried.
 If you get it to work with one cookie it's maybe worth a try.

---snip---

        ms = new MemoryStream();

        xmls.Serialize(ms, gd);

        var helpcvalue = Encrypt(Encoding.UTF8.GetString(ms.ToArray()));

        ms.Close();

        try

        {

            int helpcvallength = helpcvalue.Length;

            int helpcvalAnzahl = (helpcvallength / 4000);

            string[] helpcvalsplit = new string[helpcvallength];

            setCookie(gd.GameName + "A", (helpcvalAnzahl + 1).ToString(), 500);

            for (int i = 0; i < helpcvalAnzahl; i++)

            {

                helpcvalsplit[i] = helpcvalue.Substring(i * 4000, 4000);

                setCookie(gd.GameName + i.ToString(), helpcvalsplit[i], 500);

            }

            helpcvalsplit[helpcvalAnzahl] = helpcvalue[(helpcvalAnzahl * 4000)..];

            setCookie(gd.GameName + helpcvalAnzahl.ToString(), helpcvalsplit[helpcvalAnzahl], 500);

            RetVal = "Cookie OK: " + gd.LastSaveTime;

        }

        catch (Exception)

        {

---snap---

(2 edits)

Yep, I've come to the same conclusion. It doesn't seem possible to persist data on itch on iOS or Safari due to the iframe restriction. When I uploaded the same exact build of my game to my own site for testing, the data does persist (using IndexedDB storage).

I briefly tried experimenting with some Unity javascript plugin code to read & write cookies (and also tried window.localStorage instead) but neither one seemed to behave any different and also didn't persist data.

IF @Leafo can offer any help or insights here that would be amazing!