iOS push notifications

s.furlani

macrumors newbie
Original poster
Jan 17, 2012
6
0
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?
 

s.furlani

macrumors newbie
Original poster
Jan 17, 2012
6
0
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?
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
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.
 

s.furlani

macrumors newbie
Original poster
Jan 17, 2012
6
0
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?
 

jnoxx

macrumors 65816
Dec 29, 2010
1,343
0
Aartselaar // Antwerp // Belgium
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.
 

s.furlani

macrumors newbie
Original poster
Jan 17, 2012
6
0
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.
 

dejo

Moderator
Staff member
Sep 2, 2004
15,981
450
The Centennial State
My final purpose is to create an App that calls a WebService for periodically update its internal data.
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.
 

s.furlani

macrumors newbie
Original poster
Jan 17, 2012
6
0
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
 

dejo

Moderator
Staff member
Sep 2, 2004
15,981
450
The Centennial State
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?
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.
 

ArtOfWarfare

macrumors G3
Nov 26, 2007
8,661
4,219
To the end user, how would this appear any different from just downloading new data each time the app is opened?
 

s.furlani

macrumors newbie
Original poster
Jan 17, 2012
6
0
To the end user, how would this appear any different from just downloading new data each time the app is opened?
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...
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.