Hello
I created a hook to capture system events. I wanted to be able to detect application suspend and resume to handle my apps memory.
Runtime:addEventListener( "system", onSystemEvent );
My onSystemEvent looks like this
local function onSystemEvent( event ) DoPrint("System Event: " .. event.type .. " (Previous Event: " .. tostring(previousEvent) .. ")") if "applicationExit" == event.type then local soundChannel = audio.play( cachedSoundAppExit, { channel=3} ) -- Create the unique file before exiting createExitFile() elseif "applicationOpen" == event.type then local soundChannel = audio.play( cachedSoundAppOpenInterchange, { channel=3} ) -- http://coronalabs.com/blog/2011/12/22/using-app-url-schemes-in-ios/ native.showAlert( "Open via custom url", event.url, { "OK" } ) elseif "applicationSuspend" == event.type then -- todo save state, drop mem? local soundChannel = audio.play( cachedSoundAppSuspending, { channel=3} ) elseif "applicationResume" == event.type then --local alert = native.showAlert( "applicationResume", event.response, { "OK" } , onGenericAlertBox()) local soundChannel = audio.play( cachedSoundAppResume, { channel=3} ) GetOpenWeatherMapData() elseif "applicationStart" == event.type then local soundChannel = audio.play( cachedSoundAppStart, { channel=3} ) -- check to see if file exist if isExitFile() then DoPrint (" Last Application Run, Safe Exit Detected (Found SafeExit.flg)") end else local alert = native.showAlert( "Unknown System Event Type", tostring(event.type), { "OK" }, onGenericAlertBox() ) end return true end
Bugs:
-
applicationResume never gets fired.
-
applicationSuspend gets fired when the app resumes on the simulator and devices.
I am using build v2014.2205 on a mid 2012 Mac Book Pro Retina 15" OSX 10.9.2 and an iPhone 5 with iOS 7.1.
Config
settings = { orientation = { default = "portrait", supported = { "landscapeLeft", "landscapeRight", "portrait", "portraitUpsideDown" }, }, iphone = { plist = { UIApplicationExitsOnSuspend = false, etc...