- Home /
 
Bug? UnityObject.js shows the Install button on an iPhone 3gs
Whenever a mobile user or other non-player compatible user goes to my unity web player page, I want it to tell the user that the web player does not work on their platform.
Instead, it shows the installation button which of course is confusing for the user.
I see some browser detection in the UnityObject.js code, but I haven't spent the time trying to trace everything down. What is the UnityObject.js code supposed to do in case of an incompatible platform?
My web player is at: http://www.toldpro.com/Games/BashnBlocks
My iPhone is an unlocked 3gs 4.0.2 with User-Agent: Mozilla/5.0 (iPhone; U; CPU iPhone OS 4_0_2 like Mac OS X; en-us) AppleWebKit/532.9 (KHTML, like Gecko) Version/4.0.5 Mobile/8A400 Safari/6531.22.7
Happy to see that you posted a solution to your own question. A different approach is for your website to detect the client has a iOS device, and display completely different content, perhaps providing a link to the app store where the customer might be able to purchase the iOS version of the game. See, for example http://www.php.net/manual/en/function.get-browser.php.
I will certainly do that once I flesh out the detection of various devices and I have the apps in the different app stores. However, it seems the UnityObject.js ought to at least tell the user it cannot be installed on their platform.
Answer by RickLove · Jan 31, 2012 at 12:46 PM
I could not find an answer, but I made a way around this:
See it in action at: http://www.toldpro.com/Games/BashnBlocks You can see the default message if you look at the code source, even if the web player starts.
 function OnUnityLoaded(params) {
     if (params.success) {
         // Make the missing message go away
         var missingDiv = document.getElementById('missingMessage');
         missingDiv.parentNode.removeChild(missingDiv);
     }
 }
 function GetUnity() {
     if (typeof unityObject != "undefined") {
         return unityObject.getObjectById("unityPlayer");
     }
     return null;
 }
 if (typeof unityObject != "undefined") {
     unityObject.embedUnity("unityPlayer", "GAME.unity3d", 
       800, 600, null, null, OnUnityLoaded);
 
 }
 
               then I defined the "missingMessage" div like so (this is ASP.NET MVP 3 Razor with C#):
 <div id="game">
     <div id="missingMessage">
         @{
                             
             var isMobile = BrowserHelper.IsMobile(Request);
             var canUseUnity = BrowserHelper.CanUseUnityWebPlayer(Request);
 
 
             // TESTING
             //canUseUnity = false;
 
             if (isMobile)
             {
             <p>
                 I'm sorry, the Unity Web Player does not work on mobile devices at this time.
             </p>
             <p>
                 The web player is only compatible with:
             </p>
             <ul>
                 <li>Windows 2000/XP/Vista/7</li>
                 <li>Mac OS X 10.4 or newer</li>
             </ul>
                                 
             <p>
                 However, I am planning to put the game in the relevant app store for iPhone/iPad,
                 Android, and Windows 7 Phones in the future.</p>
             <p>
                 More Information: <a href="http://told.shapado.com/questions/why-can-t-i-play-the-game">
                     Why can't I play the game?</a></p>
             <p>
                 If you think this message is in error, feel free to try to install the Unity Web
                 Player below:
             </p> 
             }
             else if (!canUseUnity.HasValue || !canUseUnity.Value)
             {
             <p>
                 I'm sorry, it appears you may not be able to use the Unity Web Player which is required
                 to play the game in the browser. The web player is only compatible with:
             </p>     
             <ul>
                 <li>Windows 2000/XP/Vista/7</li>
                 <li>Mac OS X 10.4 or newer</li>
             </ul>
                                 
             <p>
                 More Information: <a href="http://told.shapado.com/questions/why-can-t-i-play-the-game">
                     Why can't I play the game?</a></p>
             <p>
                 If you think this message is in error, feel free to try to install the Unity Web
                 Player below:
             </p>
             }
             else
             {
             <p>
                 You need to install the Unity Web Player to play the game.
             </p>
             <p>
                 The web player is compatible with:
             </p>
             <ul>
                 <li>Windows 2000/XP/Vista/7</li>
                 <li>Mac OS X 10.4 or newer</li>
             </ul>
                                 
             }
         }
     </div>
     <div id="unityPlayer">
         <div class="missing">
             <a href="http://unity3d.com/webplayer/" title="Unity Web Player. Install now!">
                 <img alt="Unity Web Player. Install now!" src="http://webplayer.unity3d.com/installation/getunity.png"
                     width="193" height="63" />
             </a>
         </div>
     </div>
 </div>
 
               My BrowserHelper class is defined:
 public static class BrowserHelper
 {
   public static bool IsMobile(HttpRequestBase request)
   {
     // From: detectmobilebrowsers.com
     string u = request.ServerVariables["HTTP_USER_AGENT"];
     Regex b = new Regex("GOTO detectmobilebrowsers.com to get the latest value",
       RegexOptions.IgnoreCase | RegexOptions.Multiline);
     return (b.IsMatch(u) || v.IsMatch(u.Substring(0, 4)));
   }
 
   public static bool? CanUseUnityWebPlayer(HttpRequestBase request)
   {
     // Windows 2000/XP/Vista/7
     // Mac OS X 10.4 or newer
     string u = request.ServerVariables["HTTP_USER_AGENT"];
 
     Regex winVersionRegex = new Regex(@"Windows NT ((?<major>\d+)\.(?<minor>\d+))");
     Regex macVersionRegex = new Regex(@"(?<!like) Mac OS X ((?<major>\d+)_(?<minor>\d+))");
     Regex macVersionUnknownRegex = new Regex(@"(?<!like) Mac OS X");
 
     var isHighEnough = IsHighEnoughVersion(u, winVersionRegex, 5, 0) ||
       IsHighEnoughVersion(u, macVersionRegex, 10, 4);
 
     if (isHighEnough)
     {
       return true;
     }
 
     if (macVersionUnknownRegex.IsMatch(u))
     {
       return null;
     }
     else
     {
       return false;
     }
   }
 
   private static bool IsHighEnoughVersion(string userAgentText, Regex versionRegex, int minMajor, int minMinor)
   {
     var match = versionRegex.Match(userAgentText);
 
     if (match.Success)
     {
       var major = int.Parse(match.Groups["major"].Value);
       var minor = int.Parse(match.Groups["minor"].Value);
 
       if (major > minMajor)
       {
         return true;
       }
       else if (major == minMajor)
       {
         if (minor >= minMinor)
         {
           return true;
         }
       }
     }
 
     return false;
   }
 
 }
 
              Your answer
 
             Follow this Question
Related Questions
Install Unity WebPlayer Plugin from Intranet 1 Answer
streaming to iPhone and Android 0 Answers
Web player will not uninstall or install. 0 Answers
Communication iPhone Webplayer 0 Answers
Create a game for both the iPhone and the Web Player 2 Answers