Giter Club home page Giter Club logo

silentpush's Introduction

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)

silentpush's People

Contributors

ole avatar

Stargazers

Abhay Korat avatar

Watchers

James Cloos avatar Abhay Korat avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.