push notifications

Discussion in 'iOS Programming' started by s.furlani, Jan 17, 2012.

  1. s.furlani macrumors newbie

    Joined:
    Jan 17, 2012
    #1
    Hello everybody,

    I'm new to iOs development, and I have a question about how an app can receive a push notification while it's not running in background or in foreground.
    I read that there's a kind of "invisible" background, where the app can receive a push notification starting from server, i think Skype or Facebook use this techinque when you receive a private message (infact you receive it also if the app is completely closed).
    What I want to know is if in the same way we can start a request from an app that is closed asking to a server if there are new notifications every "x" minutes in an opposite way (it's not the server that sends, but is the client that asks)
    My problem is that I don't want to mantain a notification server, whereas I prefer to let the app periodically run quieries to the server.
    Is this possible? if yes, which are the iOs supported versions?
     
  2. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #2
  3. s.furlani thread starter macrumors newbie

    Joined:
    Jan 17, 2012
    #3
    Thank you so much for your answer.
    But i can't understand how it's possible that there are apps that periodically connect to a server without being effectively opened.
    For example, i think about 2 applications:
    - "Find my iphone" or similar: without being opened in background, it constantly sends the local position of the device to the server.
    - the iOs email client : it periodically checks for the new emails, sending a notification when there's a new email.

    Any ideas about that?
    If "Find my iphone" is able to periodically contact a server communicating its position, why could not my app refresh its data with a server query?
     
  4. jiminaus macrumors 65816

    jiminaus

    Joined:
    Dec 16, 2010
    Location:
    Sydney
    #4
    You (and all of us outside of Apple) are second-class developers on iOS. The Apple-provided apps have access to functionality that is denied to us.
     
  5. s.furlani thread starter macrumors newbie

    Joined:
    Jan 17, 2012
    #5
    ok, but this stuff is still not clear to me.
    Think about foursquare or other apps that helps you finding your friends (these are "second-class app"). When you walk in the neighborhood of some friends with active localization you receive a push notification, also if your application is not opened. Who told the notification server that I'm there? It's clear that my iPhone sent my position to the server.
    How do you explain that?
     
  6. jnoxx macrumors 65816

    jnoxx

    Joined:
    Dec 29, 2010
    Location:
    Aartselaar // Antwerp // Belgium
    #6
    If you read the documentation thorougly.
    You will know, that it's possible to let things like "background polling", even if your app is completely closed. it will send your location to your app at certain periods. In there you can make it send to your server like, "hey, he's there, maybe send a notification?", and then you send a notification to your user, which does open up the application active.
    I think you guys see the "multitasking" thing wrong, it's more of a fast switch thing to me. Since apple can actually kill apps that are on there, but it's still on the "multitasking", it's all memory related.

    So, read through the documentation fully, about Location things, and if you have more questions, head back.
     
  7. s.furlani thread starter macrumors newbie

    Joined:
    Jan 17, 2012
    #7
    Thank you jnoxx!
    maybe now it's clearer.
    I read the documentation more carefully, and effectively there's a section called "Implementing Long-Running Background Tasks" that explains how to implement tasks to be executed mantaining the application in background (i think depending on the memory state). There are only particular kind of tasks that can use this feature, but what i don't to know is:
    1) how long can these long-running tasks last? can i reactivate them periodically (maybe before the previous task ends) ?
    2) which are the supported versions?
    3) am I sure that if I close the app pressing "X" in the app bar, the tasks will run in background?

    My final purpose is to create an App that calls a WebService for periodically update its internal data.
     
  8. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #8
    Then I don't think you want to use push notifications at all. What you should consider is only updating the internal data (in the background, probably) when the app becomes active again.
     
  9. s.furlani thread starter macrumors newbie

    Joined:
    Jan 17, 2012
    #9
    My idea is that if the data is periodically refreshed (maybe three -four times a day) i can use local notifications instead of push notifications. But can i perform the update while the application is not active (maybe running in background with a so-called "Long-Running Background Tasks")? Do you think this solution is affordable?

    Thank you
     
  10. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #10
    I don't know about affordable but it certainly doesn't sound feasible! What you're wanting to do doesn't qualify as one of the specific app types allowed to run in the background.
     
  11. ArtOfWarfare macrumors 604

    ArtOfWarfare

    Joined:
    Nov 26, 2007
    #11
    To the end user, how would this appear any different from just downloading new data each time the app is opened?
     
  12. s.furlani thread starter macrumors newbie

    Joined:
    Jan 17, 2012
    #12
    what i want is to use local notifications and let the app update its data in background. If i wait the app to be opened it does not make sense, because i want the app to be woken up when certain conditions happen.

    I think the only solution is to implement a notification server...
     
  13. dejo Moderator

    dejo

    Staff Member

    Joined:
    Sep 2, 2004
    Location:
    The Centennial State
    #13
    Well, if you seem to know better than us what you want your app to do and why, don't let us stop you...
     

Share This Page