ZeroPush

This add-on is operated by Symmetric Infinity

Apple Push Notifications for Web Developers

ZeroPush

Last Updated: 09 January 2014

Table of Contents

ZeroPush is an add-on that provides an extremely simple and affordable way to send iOS push notifications.

Provisioning the add-on

The ZeroPush add-on can be added to an existing application through the command line as follows:

Find the plan that suits your needs.

$ heroku addons:add zeropush:inception
Adding zeropush:inception on my-app... done, v13 (free)
Use `heroku addons:docs zeropush:inception` to view documentation.

Once provisioned, the following environment variables will be available to your application.

  • ZEROPUSH_DEV_TOKEN: This is the token used to identify your application when you’d like to send notifications to applications through Apple’s sandbox gateway. For instance during development or beta testing.
  • ZEROPUSH_PROD_TOKEN: This is the token used to identify your application when you’d like to send notifications to applications through Apple’s production gateway. For instance applications downloaded from the iTunes app store.

Certificates

Execute the following command to get to the ZeroPush dashboard for your application.

$ heroku addons:open zeropush
Opening zeropush:inception for my-app... done

Navigate to the settings page for your application and upload your development and production push certificates to complete the setup. See our documentation for more information about creating certificates for your application.

Server Integration

Ruby

For Ruby applications, we provide a gem. A typical Rails app would have the following:

# in your Gemfile
gem 'zero_push'

Install the gem and run the rails generator to create a config

$ bundle install && rails g zero_push:install

This will create an initializer in config/initializers/zero_push.rb. Update the initializer to use the provided environment variables.

if Rails.env.production?
  ZeroPush.auth_token = ENV["ZEROPUSH_PROD_TOKEN"]
else
  ZeroPush.auth_token = ENV["ZEROPUSH_DEV_TOKEN"]
end

Django

For Django applications, django-zeropush provides a convenient wrapper around the ZeroPush API, as well as providing registration endpoints for device token management.

Please see the django-zeropush README for information about adding it to your application.

Client Integration

Next, you need to integrate with ZeroPush in your iOS app. We recommend using our Cocoapod.

# in your Podfile
pod "ZeroPush"

Add the following code to AppDelegate.m to have your iOS app register for push notifications

// In your application delegate
- (void)applicationDidBecomeActive:(UIApplication *)application
{
    [ZeroPush engageWithAPIKey:@"your-zeropush-auth-token" delegate:self];
    [[ZeroPush shared] registerForRemoteNotificationTypes:(UIRemoteNotificationTypeAlert |
                                                           UIRemoteNotificationTypeBadge |
                                                           UIRemoteNotificationTypeSound)];
}

- (void)application:(UIApplication *)application didRegisterForRemoteNotificationsWithDeviceToken:(NSData *)tokenData
{
    // Call the convenience method registerDeviceToken, this helps us track device tokens for you
    [[ZeroPush shared] registerDeviceToken:tokenData];

    // This would be a good time to save the token and associate it with a user that you want to notify later.
    NSString *tokenString = [ZeroPush deviceTokenFromData:tokenData];
    NSLog(@"%@", tokenString);
}

Be sure to associate the tokenString with the user. You probably want to make a request to your web app to achieve this. Remember, users can have multiple devices!

Send a push notification with cURL

$ curl -i -d "auth_token=your-zeropush-auth-token" \
  -d "device_tokens[]=49c24ca3f1fbb09915655e4fb99879510e7fe8c0836561d1e913fc988a1ae666" \
  -d "alert=How's your soup?" \
  -d "badge=4" \
  -d "sound=default" \
  "https://api.zeropush.com/notify"

Send a push notification with Ruby

ZeroPush provides a gem for use with ruby applications. An example push notification might look like the following:

require 'zero_push'

# One time initialization of the auth_token, config/initializers/zero_push.rb for instance
ZeroPush.auth_token = "your-zeropush-auth-token"

# ZeroPush expects a hash as a notification
notification = {
  device_tokens: ["49c24ca3f1fbb09915655e4fb99879510e7fe8c0836561d1e913fc988a1ae666"],
  alert: "Something really awesome just happened!!",
  sound: "default",
  badge: 1
}

# Send the notification
ZeroPush.notify(notification) # => true

Sending a push notification with django-zeropush

import zeropush

# Get a user. Can also be a custom user model in django 1.5+
the_user = User.objects.filter(username="johndoe")
zeropush.notify_user(the_user, alert="Here's some notification text", sound="default", badge_number=1)

Changing your plan

Your ZeroPush plan can be upgraded or downgraded from the command line.

$ heroku addons:upgrade zeropush:horizon
Upgrading to zeropush:horizon on my-app... done, v15 ($12/mo)
Your plan has been changed to Horizon
Use `heroku addons:docs zeropush:horizon` to view documentation.
$ heroku addons:downgrade zeropush:inception
Downgrading to zeropush:inception on my-app... done, v15 (free)
Your plan has been changed to Inception
Use `heroku addons:docs zeropush:inception` to view documentation.

Removing the add-on

The ZeroPush add-on can be removed from the command line.

This will delete your account. You will not be able to send notifications after removing the add-on.

$ heroku addons:remove zeropush
!    WARNING: Destructive Action
!    This command will affect the app: my-app
!    To proceed, type "my-app" or re-run this command with --confirm my-app
> my-app
Removing zeropush on my-app... done, v14 (free)

Support

All ZeroPush support requests should be submitted to support@zeropush.com. Please include the fact that you are a Heroku customer.