Documentation

Register Devices


Devices need to be uniquely identified to receive push notifications.

We assign every device a unique token that you can use to push it at any given time. Once the device has been assigned a token, it should be stored locally and persisted in your backend server when you have more information about the user. When you're ready to push the device, your backend server will send its token to our REST API, and we'll deliver the push notification to the corresponding device.

Please select your project type for the appropriate instructions:

Swift
Objective-C

Import the Pushy SDK by adding the following to the top of AppDelegate.swift:

import Pushy

Register devices by initializing the SDK in the didFinishLaunchingWithOptions method of the AppDelegate class and calling pushy.register():

// Initialize Pushy SDK
let pushy = Pushy(UIApplication.shared)

// Register the device for push notifications
pushy.register({ (error, deviceToken) in
    // Handle registration errors
    if error != nil {
        return print ("Registration failed: \(error!)")
    }
    
    // Print device token to console
    print("Pushy device token: \(deviceToken)")
    
    // Persist the token locally and send it to your backend later
    UserDefaults.standard.set(deviceToken, forKey: "pushyToken")
})

You should always call pushy.register() in your didFinishLaunchingWithOptions method to detect updates to the internal APNs device token, even if the device has already been registered in the past.

Import the Pushy SDK by adding the following to the top of AppDelegate.h:

#import <Pushy/Pushy-Swift.h>

Register devices by initializing the SDK in the didFinishLaunchingWithOptions method of AppDelegate.m and calling [pushy register]:

// Initialize Pushy SDK
Pushy* pushy = [[Pushy alloc]init:[UIApplication sharedApplication]];

// Register the device for push notifications
[pushy register:^(NSError *error, NSString* deviceToken) {
    // Handle registration errors
    if (error != nil) {
        return NSLog (@"Registration failed: %@", error);
    }
    
    // Print device token to console
    NSLog(@"Pushy device token: %@", deviceToken);
    
    // Persist the token locally and send it to your backend later
    [[NSUserDefaults standardUserDefaults] setObject:deviceToken forKey:@"pushyToken"];
}];

You should always call [pushy register] in your didFinishLaunchingWithOptions method to detect updates to the internal APNs device token, even if the device has already been registered in the past.


Note: Please make sure your AppDelegate class does not override any of the following APNs methods:

  1. application:didRegisterForRemoteNotificationsWithDeviceToken
  2. application:didFailToRegisterForRemoteNotificationsWithError
  3. application:didReceiveRemoteNotification:fetchCompletionHandler

Additional Note: The iOS simulator cannot register for, nor receive push notifications.