Build

Mobile Push Notifications 101: APNS, GCM, vs Pub/Sub

3 min read Michael Carroll on Jan 20, 2015

FAQs: mobile push notificationsFor our December FAQs, we discuss one of the most popular topics of the month, mobile push notifications. In this month’s episode, Stephen and I go in-depth on:

  • What’s the difference between PubNub publishing and sending mobile push notifications?
  • How is subscribing for real-time messages different from registering for mobile push notifications?
  • How do you format the message payload to target real-time and push notification delivery with one publish?
  • How do you perform high-level debugging when implementing mobile push notifications?

We’ve also written a couple of tutorials around APNS, GCM, and PubNub that will get you started nice and quick.

What’s the difference between PubNub publishing and sending mobile push notifications?

With PubNub, we send and receive messages over channels (ie. “topics”), and that gives you lots of different options on the wide variety of mobile gateways in addition to PubNub’s Data Stream Network. The PubNub mobile gateway connects directly to Google, Apple, and Microsoft for GCM, APNS, and Windows notifications.

By subscribing to a PubNub channel, all you have to do is issue a subscribe call on the channel you want to connect to. If you want to receive push notifications via the APNS gateway, you use a device registry function that’s available with the iOS SDK. With GCM, you have the Android SDK.

mobile push notification

How is subscribing for real-time messages different from registering for push notifications?

Data is received differently based on the state of the application or where the user is sitting on the app. For example, if you were to register on an APNS channel on Apple’s network, but if we also subscribe to a PubNub channel, we’ll receive the data on both of the networks depending on the state of the application. If we’re in the application and we’re live, the user will receive the data via PubNub, in real time. However, when the app is in the background, it’ll arrive when APNS sends it (Apple provides no guarantees).

How do you format the message payload to target real-time and push notification delivery with one publish?

With a single API method, we can broadcast across a wide variety of notification networks simultaneously. You can do this by defining specific keys in your payload, and in the payload, you would identify the Apple key, the GCM key, or the Windows gateway key. In that object, you paste the information that Apple is expecting to receive based on their standard docs.

Within each specific gateway, there are certain restrictions with data lengths. The entire message can be up to 32kb on PubNub, while APNS is 2kb, and GCM/Windows is 4kb.

PubNub Support

Got some questions of your own? We’re here for you! Reach out to help@pubnub.com, visit PubNub Support or tweet us @PubNub.

We also have PubNub Office Hours at our San Francisco HQ, every Wednesday from 2-5pm, where you can get your real-time questions answered in real time. Give us a heads up at office-hours@pubnub.com and let us know you’re coming.

0