Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

bmcgonag

macrumors 65816
Original poster
Mar 20, 2007
1,077
0
Texas
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.
 
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];  
    }    
}
 
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.
 
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.
 
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.
 
I'm curious: what is it that you are trying to inform the user about as they leave your app?

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.