How do iOS Push Notifications work?

88,662

Solution 1

It was too much for me to put in a comment so.

From the documentation.

Apple Push Notification service (APNs) propagates push notifications to devices having applications registered to receive those notifications. Each device establishes an accredited and encrypted IP connection with the service and receives notifications over this persistent connection. Providers connect with APNs through a persistent and secure channel while monitoring incoming data intended for their client applications. When new data for an application arrives, the provider prepares and sends a notification through the channel to APNs, which pushes the notification to the target device..

I suggest reading the documentation for more information and how to use and configure. It's all there.

Push Notifications

Solution 2

Each device can be updated with data using their own unique device tokens. This picture explains everything . .

enter image description here

Solution 3

I created an infographic to explain the workflow of push notifications. Hope this is helpful.

enter image description here

Solution 4

Device does not keep polling the server for the push notifications.

To keep it simple, consider an iPhone is connected to internet. On connecting to internet iPhone establishes connection to Apple Push Notifications server this connection is open connection which means data can be thrown to iPhone from server the moment data arrives to server.

Apple does not use HTTP protocol for Push notifications but if you understand HTTP Protocol its almost a similar methodology.

http://en.wikipedia.org/wiki/Push_technology#HTTP_server_push

Solution 5

There is a really nice exaplanation of push notifications in this article.

In iOS, apps can’t do a lot in the background. Apps are only allowed to do limited set of activities so battery life is conserved.

But what if something interesting happens and you wish to let the user know about this, even if they’re not currently using your app?

Share:
88,662
Andy Hin
Author by

Andy Hin

Updated on June 11, 2021

Comments

  • Andy Hin
    Andy Hin about 3 years

    How do iOS "push" notifications get delivered to a particular device without that device needing to poll a server?

    For example, let's say I have received a new message on Facebook. Facebook notifies Apple that my device should receive a notification as such. But how does Apple know which device/IP to push the message to?

  • CMCDragonkai
    CMCDragonkai about 10 years
    So Apple maintains a static IP to your device?
  • Vladimir
    Vladimir about 10 years
    I was wondered when understood that my server have to send a notification to APNS FOR EACH TARGET DEVICE! :(
  • Mugen
    Mugen about 8 years
    Any idea what is the usage of the Device Token? Is it used for encrypting communication between the APNS server and the App or elsewhere?
  • Hitechcomputergeek
    Hitechcomputergeek about 8 years
    @CMCDragonkai The device establishes the connection, not the server.
  • kisor
    kisor over 7 years
    @Panama jack hello sir how long will the message remain in the server if i put note.expiry = Math.floor(Date.now() / 1000) + 43200 sec than will it remain up to 12 hrs . i just want to know does expiry time has limit or it goes our way.
  • D4ttatraya
    D4ttatraya over 7 years
    @Mugen: Device token is used by APNS to identify which device it is supposed to forward the payload sent by provider!
  • Howiecamp
    Howiecamp over 7 years
    @Karan - Is there a distinction between notifications which are for a user (e.g. "Hey user you have a message!") and those that are meant for to wake up an app and silently tell it to do some background processing?
  • Howiecamp
    Howiecamp over 7 years
    What do they use if not http?
  • Karan Alangat
    Karan Alangat about 7 years
    @Howiecamp If you are using push notification, you will get notified whenever a notification has been received if the app is running. Also the active notification details are accessible , when user taps the notification from notification center and launches the app. During this time you can perform the processes that you wish to do.
  • AV94
    AV94 almost 6 years
    so the devices maintain a long polling/socket kind of connection always with APN service? If such is the case then how does APN service handle so many connections - If a server can hold 50k connections and there are 500 million users always, service at least needs 10000 servers right. Is this a practical scenario?
  • GvSharma
    GvSharma almost 6 years
    @KaranAlangat, How do Badge Count handled here? How server knows about it?
  • Karan Alangat
    Karan Alangat almost 6 years
    @GvSharma Usually we will get badge information from Notification Payload. We can change it from app also.
  • GvSharma
    GvSharma almost 6 years
    how server knows unseen messages in app?did app needs to call anything?
  • Radu Murzea
    Radu Murzea over 5 years
    I think step 5 is the confusing one and triggered this question. It's a bit unclear to me as well how that part works, especially since your phone a lot of times can be behind a NAT router that typically rejects incoming traffic that wasn't requested.
  • fishinear
    fishinear about 5 years
    @AV94 That is for Apple to handle, but I would estimate 50k connections per server to be extremely underestimated. I would expect more in the order of 10 million connections per server. It all depends on the amount of traffic that they need to handle.
  • Chris Huang-Leaver
    Chris Huang-Leaver about 5 years
    @AV94 this was why I Google this question. I find it doubtful that 'long poll' would be the best solution Apple could think of. Just observing how wobbly my data connection gets when I use the phone on a train. I guess anyone who actually knew would have signed an NDA. It would be fun to guess.
  • not2savvy
    not2savvy about 3 years
    Great infographic. However, it misses final step 6: APNS send notification to the device that APNS knows as connected to the token.