{"id":928,"date":"2018-08-28T18:25:52","date_gmt":"2018-08-28T18:25:52","guid":{"rendered":"http:\/\/www.netexl.com\/blog\/?p=928"},"modified":"2018-08-28T18:39:17","modified_gmt":"2018-08-28T18:39:17","slug":"phaser-cordova-mobile-app-crashing-on-ios","status":"publish","type":"post","link":"https:\/\/www.netexl.com\/blog\/phaser-cordova-mobile-app-crashing-on-ios\/","title":{"rendered":"Phaser Cordova Mobile App Crashing on iOS"},"content":{"rendered":"<p>I recently decided to compile Phaser games to iOS and publish to The App Store. The games\u00a0were already published\u00a0on Google Play Store\u00a0for Android and worked without any issues. I faced few issues after compiling\u00a0Phaser games\u00a0for iOS. The first issue which I faced was the game crashing randomly on iOS. After doing further research I found <a href=\"https:\/\/software.intel.com\/en-us\/forums\/intel-xdk\/topic\/629285\" target=\"_blank\">this article<\/a>\u00a0on Intel XDK forum\u00a0which turned out\u00a0to be the reason for crash. The games were written a while back with older versions of Phaser and I did not get time to upgrade and test this\u00a0with newer versions of Phaser (CE and higher) so I decided to try the fix specified in <a href=\"https:\/\/software.intel.com\/en-us\/forums\/intel-xdk\/topic\/629285\" target=\"_blank\">this thread<\/a> and voila,\u00a0it worked just fine.<\/p>\n<p>Here is the code which I borrowed from the thread<\/p>\n<pre class=\"lang:default decode:true\">var mygame;\r\nwindow.onload = function () {\r\n    mygame = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, \"mygame\");\r\n    mygame.state.add(\"Boot\", Boot);\r\n    mygame.state.add(\"Loading\", Loading);\r\n    mygame.state.add(\"MainMenu\", MainMenu);\r\n    mygame.state.add(\"TheGame\", TheGame);\r\n    mygame.state.start(\"Boot\");\r\n\t\r\n    function onPause() {\r\n        if(!mygame.paused) {\r\n            mygame.gamePaused();\r\n        }\r\n    }\r\n  \r\n    function onResume() {\r\n        setTimeout(function() {\r\n            if(mygame.paused) {\r\n                mygame.gameResumed();\r\n            }\r\n        }, 0);\r\n    }\r\n \r\n    document.addEventListener('pause', onPause, false);\r\n    document.addEventListener('resume', onResume, false);\r\n\t\r\n}\r\n<\/pre>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I recently decided to compile Phaser games to iOS and publish to The App Store. The games\u00a0were already published\u00a0on Google Play Store\u00a0for Android and worked without any issues. I faced few issues after compiling\u00a0Phaser games\u00a0for iOS. The first issue which I faced was the game crashing randomly on iOS. After doing further research I found this article\u00a0on Intel XDK forum\u00a0which turned out\u00a0to be the reason for crash. The games were written a while back with older versions of Phaser and I did not get time to upgrade and test this\u00a0with newer versions of Phaser (CE and higher) so I decided to try the fix specified in this thread and voila,\u00a0it worked just fine. Here is the code which I borrowed from the thread var mygame; window.onload = function () { mygame = new Phaser.Game(window.innerWidth, window.innerHeight, Phaser.AUTO, &#8220;mygame&#8221;); mygame.state.add(&#8220;Boot&#8221;, Boot); mygame.state.add(&#8220;Loading&#8221;, Loading); mygame.state.add(&#8220;MainMenu&#8221;, MainMenu); mygame.state.add(&#8220;TheGame&#8221;, TheGame); mygame.state.start(&#8220;Boot&#8221;); function onPause() { if(!mygame.paused)[&#8230;]<\/p>\n","protected":false},"author":5,"featured_media":293,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,27,19,4,22],"tags":[],"class_list":["post-928","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-intel-xdk","category-ios","category-mobile","category-phaser","category-quick-tip"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/posts\/928","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/comments?post=928"}],"version-history":[{"count":2,"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/posts\/928\/revisions"}],"predecessor-version":[{"id":931,"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/posts\/928\/revisions\/931"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/media\/293"}],"wp:attachment":[{"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/media?parent=928"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/categories?post=928"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.netexl.com\/blog\/wp-json\/wp\/v2\/tags?post=928"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}