Alert after App is "closed" (Home button pressed)

Discussion in 'iOS Programming' started by bmcgonag, Oct 29, 2011.

  1. bmcgonag macrumors 65816

    bmcgonag

    Joined:
    Mar 20, 2007
    Location:
    Texas
    #1
    With the iPhone allowing apps to continue running in the background, how do you get your Alert view to pop-up (vibrate and tone with alert at top, so notification) if they've pressed the home button?

    I've searched around and don't see it anywhere, but on the Simulator it doesn't work for me until I go back into the app, then my Alert pops up.

    Otherwise, thanks to you guys and the tutorials I've found online, I've got things working.
     
  2. firewood macrumors 604

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #2
    Posting a local notification might work from the background.
     
  3. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #3
  4. smashatom macrumors newbie

    Joined:
    Oct 29, 2011
    Location:
    Taipei
    #4
    Something like this will work in your App Delegate - this one will play a "goodbye" sound, but filling in alertBody will get you a pop up as well.

    Code:
    - (void)applicationDidEnterBackground:(UIApplication *)application
    {
        // Create a new notification
        UILocalNotification* alarm = [[[NSClassFromString(@"UILocalNotification") alloc] init] autorelease];
        if (alarm)
        {
            alarm.fireDate = nil;
            alarm.repeatInterval = 0;
            alarm.soundName = @"goodbye.caf";
            alarm.alertBody = nil; 
            alarm.hasAction=NO;
            [application presentLocalNotificationNow:alarm];  
        }    
    }
    
     
  5. bmcgonag thread starter macrumors 65816

    bmcgonag

    Joined:
    Mar 20, 2007
    Location:
    Texas
    #5
    I will look at your solutions, as I think it may still help answer my question, and thank you all for the responses, but I think my intent is misunderstood. I don't want to pop-up an alert because they pressed the Home button, but I want a timed alert to still come up even if the home button has been pressed so that they can use another app while waiting.

    I hope that is more clear, and sorry for the initial confusion.
     
  6. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #6
    If you saw the Docs, that's what you want right? When they press the button, you can fire a UILocalNotification, then they see that popping up in whatever app they are in, or on the home screen, or on their lock screen.
    That's what it's for.
     
  7. bmcgonag thread starter macrumors 65816

    bmcgonag

    Joined:
    Mar 20, 2007
    Location:
    Texas
    #7
    Still at work, haven't gotten to look over it yet, but it sounds exactly like what I'm looking for.

    I do appreciate all of the input.
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    I'm curious: what is it that you are trying to inform the user about as they leave your app?
     
  9. bmcgonag thread starter macrumors 65816

    bmcgonag

    Joined:
    Mar 20, 2007
    Location:
    Texas
    #9
    It's a reminder app with a twist. I'm really just trying to see what all I can do with it. I made the app in Javascript and Html 5 a year or so ago. Now I'm trying to re-make it in Xcode.
     

Share This Page