Posted on by

launchArgs

The local variable, launchArgs, will hold any data that is passed to your app when it is not in the foreground (such as notification event data). IMPORTANT: The line below must be placed in main.lua and it MUST be the first line of code or it will not work:

local launchArgs = ...

Then, elsewhere in your app (somewhere after your notification listener function), you check to see if any launchArgs were detected, and if so, you simply invoke your notification listener manually.

Here’s an example:

Line 1 is where you declare the launchArgs variable.

Lines 3-8 is your notification listener that will tell your app what to do in the event a notification occurs.

Line 11 is where you tell your app to start listening for notification events.

Finally, lines 13-16 is where you check if any notification data is in launchArgs, and if so, you manually invoke your notification listener (lines 3-8) and pass launchArgs.notification as the first argument (notification event data).

IMPORTANT: In order for any of this to work, you need to set UIApplicationExitsOnSuspend to false in your build.settings file. See the example below:


iphone = {
plist = {
UIApplicationExitsOnSuspend = false
}
}

So to re-cap, what I just showed you is how to detect notifications when your app is NOT in the foreground, meaning, the user is not currently in your app. For a more general Local Notifications how-to, see last week’s post.

More Daily Build Updates

Additionally, Corona Subscribers will be glad to hear that there’s been tons of bug fixes to come through the Corona Daily Builds since I announced the availability of Local Notifications in Build 625 last week.

Here’s a quick rundown of all that’s been fixed in just the last few builds (626-631):

Android

  • Fixed issue where a web popup would prevent the back key from exiting the app.
     
  • Fixed bug where network.download() would crash if file was larger than 24 MB. Also fixed issue where network.request() and network.download() was blocking the UI thread (casenums: 8353, 8413).
     
  • Fixed bug where search button would close the activity indicator (casenum: 8410).
     
  • Fixed random crash caused by exiting out of an app that listens to heading/compass data (casenum: 8432).
     
  • Fixed bug where accelerometer, gyroscope, and heading/compass would yield wrong values on landscape tablets (casenum: 8260).
     
  • Fixed bug where opening/closing the physics keyboard would restart the app if it had a fixed orientation (casenum: 8445).
     
  • Fixed crash that sometimes occurred if the app was exited while a web popup was loading a new page (casenum: 8473).
     
  • Fixed out-of-memory crash caused by loading too many images (casenum: 1298).
     
  • Got rid of the harmless “can’t open” log messages caused by loading asset files.
     

iOS

  • Updated InMobi SDK to Build 3.0.2 which fixes several issues, including ones related to app crashes and geo-data permissions popups (casenum: 8439).
     
  • Fixed several important OpenAL audio-related bugs affecting iOS 5 (just in time!), as well as other OpenAL bugs (casenums: 8401, 8186, 8247—see the Daily Build release notes for full descriptions).
     

Other

  • Physics: Fixed bug where “length”, “frequency”, and “dampingRatio” properties were not getting properly set (casenum: 8291).
     

Can you believe all those changes are from only six builds?!

It just goes to show how much work our engineering team does on a daily basis, and also highlights a HUGE benefit to becoming a Corona subscriber: you get to download all these bug fixes (as well as new features!) as soon as they’re pushed in!

Stay tuned for more updates, and in the meantime, become a subscriber today.


Posted by . Thanks for reading...

7 Responses to “Daily Builds Update (626-631)”

  1. Matthew

    Any ETA on Android In-App Purchases? The second that daily build goes live is the second I purchase my subscription! :)

    Reply
  2. James

    Has anyone actually got this to work?

    I have tried exactly the code listed above without success and then tried the simplest form I could think of:


    local launchArgs = ...

    if launchArgs and launchArgs.notification then

    native.showAlert("Time to play", "Play", {"OKey"})
    local text = display.newText("Processing notification......", 0, display.contentHeight, system.nativeFont, 20)
    text:setTextColor(255, 0, 255)
    text.x = display.contentWidth / 2
    text.y = display.contentHeight / 2

    else

    system.scheduleNotification(15, { alert = "This is the alert text", badge = 1, sound = "alarm.caf" })
    local text = display.newText("Notification set.....", 0, display.contentHeight, system.nativeFont, 20)
    text:setTextColor(255, 0, 255)
    text.x = display.contentWidth / 2
    text.y = display.contentHeight / 2
    end

    The notification itself works, when the app is either exited or in the background the alert will go off, however when I tap the alert, if the app is suspended (as in most cases) it is simply brought into the foreground but doesn’t go through the “launchArgs…” bit and so only displays where it left off, i.e. “Notification set…..”. If the app is exited, as would be the case if the phone was rebooted or you manually shut down the app, it starts up and shows the splash page, then exits immediately – no alert and no text saying “Processing notification………”

    Hopefully it’s just me but currently it seems like this function doesn’t work at all.

    What am I missing?

    Reply
  3. James

    Problem solved, it seems this was broken in build 2011.703 for iOS 5.1 at least.
    Not sure exactly which build it was fixed in but I have upgraded to the latest daily build and it now works.

    Reply
  4. Vik

    I am unclear as to what this is supposed to do? I followed your other post (the Local Notifications) and I don’t see any difference when I put in on an Ipad…

    functionality works the same..

    even when the application is in the background, I still get notification and they still run the same way…

    what is the scenario I am missing?
    am I missing something?

    Reply

Leave a Reply

  • (Will Not Be Published)