Skip to content

Instantly share code, notes, and snippets.

@JohannesDeml JohannesDeml/README.md
Last active Mar 26, 2020

Embed
What would you like to do?
Remove Unity Mobile Notification Warning for WebGL builds

Remove warning

Unity has a warning when running a webgl build on mobile (iOS, Android). In order to remove it, just add this file to an editor folder.

Logic

The script will run after the build has completed and replace the checks from all generated javascript files.

Support

  • Tested with Unity 2019.3, but should work with any version
  • Works with Name Files as Hashes, since it looks for all js files in the Build folder
  • Only runs when building for WebGL, so you can use it for a multiplatform project

Further Notes

  • Unity adds this note, since the builds oftentimes don't work for mobile, so oftentimes it does make sense to include the info.
  • You might need to empty your browser cache to get the new javascript file without any warnings
// --------------------------------------------------------------------------------------------------------------------
// <copyright file="RemoveMobileSupportWarningWebBuild.cs" company="Supyrb">
// Copyright (c) 2020 Supyrb. All rights reserved.
// </copyright>
// <author>
// Johannes Deml
// public@deml.io
// </author>
// --------------------------------------------------------------------------------------------------------------------
using System.IO;
using UnityEditor;
using UnityEditor.Callbacks;
using UnityEngine;
namespace Supyrb
{
public class RemoveMobileSupportWarningWebBuild
{
[PostProcessBuild]
public static void OnPostProcessBuild(BuildTarget target, string targetPath)
{
if (target != BuildTarget.WebGL)
{
return;
}
var buildFolderPath = Path.Combine(targetPath, "Build");
var info = new DirectoryInfo(buildFolderPath);
var files = info.GetFiles("*.js");
for (int i = 0; i < files.Length; i++)
{
var file = files[i];
var filePath = file.FullName;
var text = File.ReadAllText(filePath);
text = text.Replace("UnityLoader.SystemInfo.mobile", "false");
Debug.Log("Removing iOS warning from " + filePath);
File.WriteAllText(filePath, text);
}
}
}
}
@JJeonggg

This comment has been minimized.

Copy link

JJeonggg commented Mar 3, 2020

it works. but in IOS,make sure u delete the cache data of the browser. THANKS!

@JohannesDeml

This comment has been minimized.

Copy link
Owner Author

JohannesDeml commented Mar 3, 2020

it works. but in IOS,make sure u delete the cache data of the browser. THANKS!

Good point, added it to the readme :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.