how can I make my application to run in background???

Discussion in 'iPhone/iPad Programming' started by sspbond007, Aug 27, 2008.

  1. macrumors member

    Joined:
    Aug 19, 2008
    #1
    Hi,

    Can please somebody help me, how can I make my application to run in background?
    For eg. My application continuously ping server to get and send some data on the basis of user's setting. Currently when I run my application it works perfectly.I used NSTimer to perform that task repeatedly after specific time, set by user. Now if I stop the application the whole process stops, but I need is that, even after user stops the application it should not terminate. The task that is performed by NSTimer repeatedly must go on as it is. Means I just want to run my application in background, ever if user stops it or any interruption occurs, application should not terminate.

    thanks
     
  2. macrumors 65816

    Joined:
    Jun 29, 2007
    #2
    You can't, Apple does not allow applications to run in the background.
     
  3. macrumors 603

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #3
    Didn't Apple say you could do..

    something... about the... it's always connected... and the little badge on the icon in the home screen?

    I wasn't paying much attention to the keynote at that point because I had no plans for making an application that runs in the background.


    I'm confused about what your application does... why does it need to be running in the background?
     
  4. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #4
    No. They said that at some future point in time (should be September/firmware 2.1 but we'll see) there would be facilities for third part developers to send push notifications over the air from their own servers. Limited code stubs would be allowed to act on these notifications which would have the ability to update the badge icon. This is very different to running in the background.
     
  5. macrumors newbie

    Joined:
    Jul 14, 2008
    #5
    So... In the future...

    The way you would do this is that you would have a proxy client running on a server somewhere doing your pings. When something important happens and iPhone application needs to notified, you'll be able to send a new badge icon and a beep to the iPhone, via an Apple service, notifying the user that something important has happened and to launch the iPhone application to get the notification.

    The reason for this is clear...

    Background apps have a bad history on mobile devices. They chew up batteries really fast, especially if you're polling a server somewhere. Also, they tend to cause stability and performance issues.

    Personally, I think Apple made the right choice here.
     
  6. macrumors member

    Joined:
    Aug 21, 2008
    #6
    it is not available but it will be soon as what they said..
     
  7. macrumors 68000

    Joined:
    Feb 12, 2008
    Location:
    Illinois
    #7
    You cannot run applications in the background. In the keynote, Apple was addressing push which is pretty much what SMS is. The application isn't running in the background...but when you can receive SMS while the application is closed.

    This is good because if you have AIM, you don't want your buddy list to update while AIM is in the background...you don't see the list anyway! You only want it to update while you're in the application. The only thing you want in the background is receiving IMs.

    As for your application, I think you can easily use push. Of course it would require some server work, but basically when the application is closed, have the server send the information to the device instead of the device pinging the server. So you'd have the server on a timer.
     
  8. macrumors newbie

    Joined:
    Jun 26, 2008
    #8
    Hello

    I also have the same problem , i want to run my application in background, but iphone SDK not allow it.

    Now i want to run my application in foreground and do my work and after that i will close my application forcefully.

    But i want to know that can i invoke or open my application by using any message or alarm. Means i'll generate a alarm when i'll get my data and display a message popup for that. when user will touch on that message i want to invoke my application directly.

    How can i do this please help me in that..
     
  9. macrumors 68000

    Joined:
    Feb 12, 2008
    Location:
    Illinois
    #9
    You cannot. The only way is if you wait until September when Apple releases push. Then you'd have to set up a whole server and stuff to push alarms to the phone.
     
  10. macrumors 6502

    mccannmarc

    Joined:
    Aug 15, 2008
    Location:
    Manchester, UK
    #10
    although the recent death of steve jobs may delay push release date ;) haha
     
  11. macrumors newbie

    Joined:
    Jun 26, 2008
    #11
    Thanks

    Thanks for your reply and great knowledge share.
    You mean before push i can't invoke my application using alarm or anything directly, rite.
    Is there any alternative way to do that ? acutely i just want to invoke my application directly using alarm.

    i am just trying to make you clear what i want for my application. please make me clear it again with your great knowledge.


    Thanks in advance.
     
  12. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #12
    There is no way to have an app start via an alarm. There are no work arounds unless you target jailbroken phones which means your app will not go on the app store
     
  13. macrumors newbie

    Joined:
    Jul 29, 2008
    #13
    First, I think, according to the keynote presantation, background app is a huge power consumer, so, :apple: developed so called "Notification service", but till now, there is no any further news about when this notification service will go online.

    Second, Notification service is not aim to start you app by receive a "notification", it's just a notification to the user, and show the budge icon on the right top of your app icon to notify the user that you should start this app and check for something new.

    Besides, notification is really a good idea, but I still think people still have some requirement to run the application in the background no matter how much power it will consume.:rolleyes:
     
  14. macrumors G3

    TuffLuffJimmy

    Joined:
    Apr 6, 2007
    Location:
    Portland, OR
    #14
    access to that sort of information is not allowed.
     
  15. macrumors 6502a

    Joined:
    Mar 13, 2008
    #15
    I accidentally found a tutorial that shows how to make your application run in the background... but he only got as far as testing and proving it works in the sim. As far as I can tell no one has done it on a device, and who knows if you could successfully get by apple. I can't find the site now...

    I don't want apps running in the background. I got deep into palm programming and the device, and if you have too you know that palm apps can run in the background, and a lot do. This cause sooooooo many problems for the user and developer, it's not worth it. And also, as Jobs pointed out, then you need RAM managers and that sort of thing.
     
  16. macrumors 603

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #16
    Technical detail: exit() is in the public API's, but its use in not recommended according to the guidelines (HIG).
     
  17. Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #17
    This is a very harsh way to exit the app: it does not cause the normal quit notifications to get called that an app would often use to save state and so on. The method I posted in the other thread does.
     
  18. macrumors 603

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #18
    The Simulator allows background processes. They won't work on an actual (non-jailbroken) device.
     
  19. macrumors newbie

    Joined:
    Sep 21, 2008
    #19
    why does not application run in the background.
    Who can answer my question: how does iBackList work if it can not run in the background? Main feature of it is filtering incoming/outgoing calls and sms per contact
     
  20. macrumors G3

    TuffLuffJimmy

    Joined:
    Apr 6, 2007
    Location:
    Portland, OR
    #20
    That can only be installed on Jailbroken phones. ie phones that have been hacked.
     
  21. macrumors 603

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #21
    It probably isn't an app store app, uses API's not supported by the SDK, and thus won't run on any non-jailbroken devices.

    Most developers in this forum only care about SDK apps.

    .
     
  22. macrumors newbie

    Joined:
    Oct 7, 2008
    #22
    iBlacklist works in the background because it is a jail broken application

    *whoops didnt see the second page lol
     
  23. macrumors newbie

    Joined:
    Jun 26, 2008
    #23
    Hello



    Running app in background consumes lots of battery power that is not good for device, thats why background process is not supported and preferred not to use this process in application.
     
  24. macrumors newbie

    Joined:
    Jan 1, 2009
    #24
    Annoying Anti-Comments

    Isn't it annoying when others dictate how your app should or shouldn't work? Why should apple limit the ability for background apps? The google phone has this ability via the ability to run services.

    Yes, it causes battery performance issues. But, if for instance you want to sell an alarm clock... the user of your software needs to 'remember' to start the alarm clock up. How about reminders... oh.. the user needs to remember to start your reminder app? Sure you can use notification for some of this... but more sophisticated apps are going to need the ability to actually run code.

    Apple can get away with their own 'background' apps such as their alarm clock on the iPhone. But, apple knows better than 'developers' and 'users'... this is locked down for developers and open for Apple. Let the user decide if an app should run in the background. They can remove the app if they're unhappy with the battery degradation.

    ~end rant.
     
  25. macrumors 603

    Joined:
    Jul 29, 2003
    Location:
    Silicon Valley
    #25
    Apple can get away with it because they wrote the app and the OS and know exactly how much memory/battery/CPU-cycles needs to be budgeted to (mostly) meet the advertised specs for an iPhone.

    If users are unhappy, a very large number of them will have no clue what to remove and instead blame Apple.

    .
     

Share This Page