Sandbox Push Notifications

Mushthak Ebrahim
3 min readJun 8, 2023

Test push notifications without worrying about disrupting real users

Photo by Brooke Lark on Unsplash

Push notifications are valuable tool for app developers looking to increase engagement and retention with their app.

It is important for developers to test push notifications in the sandbox environment before sending them to production, as this allows them to ensure that their push notifications are working correctly and are formatted correctly. This can save time and prevent issues from occurring when the push notifications are sent to real users

There are two main types of push notifications: sandbox push notifications and production push notifications.

Sandbox push notification

Sandbox push notifications are sent to a device when it is running in the sandbox environment, which is a simulated environment that is separate from the production environment.

They are not delivered to real users, but are instead sent to a device that is used for testing purposes.

This allows developers to test push notifications without worrying about disrupting real users.

This means that you will need to ensure that your app running in your device is build using Apple developer certificate.

Production push notification

Production push notifications, on the other hand, are sent to real users when an app is running in the production environment. These push notifications are delivered to the user’s device just like any other push notification, and can be used to alert the user to new content or events within the app, or to prompt the user to take some action.

This means your app is running in your device is build using Apple distribution certificate

Testing in Sandbox

Example curl request to test push notification:

curl -X POST \
-H "END_STREAM" \
-H "END_HEADERS" \
-H ":method: POST" \
-H ":scheme: https" \
-H ":path: /3/device/00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0" \
-H "host: api.sandbox.push.apple.com" \
-H "authorization: bearer eyAia2lkIjogIjhZTDNHM1JSWDciIH0.eyAiaXNzIjogIkM4Nk5WOUpYM0QiLCAiaWF0I
jogIjE0NTkxNDM1ODA2NTAiIH0.MEYCIQDzqyahmH1rz1s-LFNkylXEa2lZ_aOCX4daxxTZkVEGzwIhALvkClnx5m5eAT6
Lxw7LZtEQcH6JENhJTMArwLf3sXwi" \
-H "apns-id: eabeae54-14a8-11e5-b60b-1697f925ec7b" \
-H "apns-push-type: alert" \
-H "apns-expiration: 0" \
-H "apns-priority: 10" \
-H "apns-topic: com.example.MyApp" \
-d '{ "aps" : { "alert" : "Hello" } }' \
https://api.sandbox.push.apple.com/3/device/00fc13adff785122b4ad28809a3420982341241421348097878e577c991de8f0

The request uses HTTP headers to provide the push key ID and the auth key to authenticate the request with the Apple Push Notification service (APNS). The request includes various HTTP headers that provide additional information about the push notification, such as the push type, expiration, priority, and topic.

The difference is in the request url. For sandbox the url is api.sandbox.push.apple.com and for production it is api.push.apple.com

Thinks to consider while testing

  1. Test on multiple devices: Test on a variety of devices, including different models and operating system versions. This will help ensure that the push notifications are working properly on all devices.
  2. Testing with different payloads: Test with different payloads, including different combinations of alert messages, sounds, and badges. This will help ensure that the push notifications are working properly and are formatted correctly for all possible payloads.
  3. Test with different app states: Test with the app in different states, including when the app is in the foreground, background, and not running. This will help ensure that the push notifications are delivered and handled correctly in all app states.
  4. Test with different network conditions: Test under different network conditions, including different types and speeds of networks. This will help ensure that the push notifications are delivered properly under all network conditions.

--

--

Mushthak Ebrahim

Lead @Tata Consultancy Services | iOS, Android, Flutter, Angular, ML, Python, Java Spring Boot