views:

678

answers:

3

Hi all, Is there any way to start sound or pop-up message from closed iPhone app. Simply like "receive SMS"

+6  A: 

I don't believe so. Apple has stated that no third party apps can run in the background (even though some of their apps do this). This is why there was a big deal about "push notifications" last summer (that has since gone no where, unfortunately) - this would allow an app to be sent some data from a server, and then appropriately respond to it.

You might be able to accomplish this if you write an app for a jailbroken iPhone, but then only those users who have jailbroken their phone would be able to install and use your app.

Andy
Apple demo'd Push Notifications at the iPhone OS 3.0 keynote:http://i.gizmodo.com/5171796/iphone-30-os-guide-everything-you-need-to-know
GrahamS
What a difference a year and a half makes. This info is now obsolete. I posted an updated answer for people who are finding this question now.
Brad Smith
+1  A: 

Andy is right but Apple promised to enable their push system for 3th parties as well. So, I think you could just wait till they release it... no idea when though.

Cimm
Push was initially supposed to be available by September 2008. Months later it's still not available and Apple's not talking about it. It might still happen but I wouldn't make any plans which depend on it.
Tom Harrington
A: 

Yes, this has actually changed after the question was initially answered.

There are currently at least two ways for a closed application to play a sound or a popup.

  1. An app can register for a Local Notification while it is running, that will be called at a future time even if the app is closed. The notification will display a popup and optionaly play a sound or set a badge on an application's icon. Implementing this is easy:

        id localNotif = [[NSClassFromString(@"UILocalNotification") alloc] init];
        if (!localNotif) {
            return;
        }
    
    
    
    [localNotif setTimeZone:[NSTimeZone defaultTimeZone]];
    [localNotif setAlertBody:NSLocalizedString(@"Hello!",nil)];
    [localNotif setAlertAction:NSLocalizedString(@"Hello", nil)];
    [localNotif setSoundName:UILocalNotificationDefaultSoundName];
    [localNotif setFireDate:[[NSDate date] addTimeInterval:(60*60)]];           
    [localNotif setFireDate:[[NSDate date] addTimeInterval:(24*60*60)]];
    [[UIApplication sharedApplication] scheduleLocalNotification:localNotif];
    [localNotif release];
    
  2. An app (with the user's permission) can register itself with a remote server (yours or a service provider) to receive push notifications delivered to it from you (via Apple's system). Once received, the App will optionally display a popup, play a sound, and/or change the badge on an applications icon. There is sample code in the Apple documentation for implementing the iPhone side of this, and also a few open source projects floating around for the server side. You can bypass having to implement your own server side by using a service like Urban Airship.

Brad Smith