All Projects → ole → SilentPush

ole / SilentPush

Licence: other
An iOS test app for testing silent push notifications and background fetching.

Programming Languages

swift
15916 projects

Silent Push

An iOS test app for testing silent push notifications and background fetching.

Written by Ole Begemann, March 2016.

Swift 2.1 (Xcode 7.2), iOS 9.2.

Overview

The app monitors whenever it receives a push notification (regardless if the app is in the background or currently active) or the OS wakes it up for a background fetch and saves these events in a list. When an event occurs while the app is in the background, it increments the app icon badge number to tell you something has happened.

You can use the app to test how push notifications and background fetch events are delivered by the OS under varying conditions, such as permission settings or power source.

Screenshot

Usage

  1. Clone the repository and open the project in Xcode.

  2. If you want to send push notifications for testing, you must do the following:

    1. Change the app’s bundle identifier in Xcode to some value that works for your Apple ID, e.g. com.yourdomain.SilentPush.
    2. Register an App ID and create a push certificate (for the development environment) on Apple's developer site.
  3. Run the app from Xcode. On first launch the app will ask you for permission to send you notifications. It does this only to be able to set the app icon badge number on the home screen (incremented whenever the app receives a silent push or background fetch event while it is in the background), so I suggest you allow notifications. No user permission is required for an app to receive silent push notifications, however, so feel free to not give permission.

  4. Copy the device’s push notification token in the Xcode console, e.g.:

    application(_:didRegisterForRemoteNotificationsWithDeviceToken:): <66175d5c 3ac68a6a df30a980 84697476 ef7a8f29 127f7f1f c487839f a3ba7796>
    

    You’ll need the token to send push notifications to your device for testing.

  5. Observe how the app receives push notifications and background fetch events in different states:

    1. Active in the foreground.
    2. Suspended in the background.
    3. After force-quitting it from the app switcher.
    4. After changing the app’s permissions to receive notifications and/or perform Background App Refresh in Settings.

How to Send Push Notifications

I recommend Mattt Thompson’s Houston for sending push notifications from the command line (part of the Nomad set of command line tools).

After you have installed Houston and downloaded your push notification certificate from Apple, sending a silent push notification is as easy as this:

$ apn push <TOKEN> \
    --certificate <PATH_TO_PUSH_CERT> \
    --payload '{ "aps": { "content-available": 1 } }'

where TOKEN is the device token without spaces, e.g. 66175d5c3ac68a6adf30a98084697476ef7a8f29127f7f1fc487839fa3ba7796, and PATH_TO_PUSH_CERT is the path to your push certificate. Feel free to experiment with varying payloads. The "content-available": 1 key-value pair specifies a silent push notification.

Test Results

(todo)

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].