Skygear Push Basics
You need to register the devices before sending push notifications to the devices.
There are THREE platform specific steps to register for push notification on iOS to ensure Push Notification working with Skygear.
- Registering device at Skygear and Apple Push Notification Service
- Request authorization to display notifications
- Update your device token on Skygear
After completing these three steps, you will be able to receive push notification sent via Skygear.
Registering device at Apple Push Notification Service
Here's how.
It is suggested that you register a device when your app launches every time. Since the Skygear container remembers the device ID, it will reuse the existing device ID whenever you try to register the current device more then once.
Now, you are able to request for a remote notification token at some point in your app.
This is an example on how you may register a remote notification when the application launches at didFinishLaunchingWithOptions
.
Sample codes are shown together in the Request authorization to display notifications session.
Request authorization to display notifications
You should make sure your app has the permission to send user push notifications when the app is in the background according to the Apple's documentation.
If you do not request and receive authorization for your app's interactions, the system delivers all remote notifications to your app silently. It is advised to ask the user for permission before registering Apple Push Notification Service .
Here's how you can request for APN and notification handler events:
Update your device token on Skygear
When a device token is registered with Apple Push Notification Service, you
should register the device once again by updating the registration
with a device token at didRegisterForRemoteNotificationsWithDeviceToken
When the device is registered on the remote server, a device ID will be
available to the client application. If you register the current device
using the above convenient methods, the device ID is returned from
registeredDeviceID
property on the container.
Sending push notification to users
Okay, now we are ready to send push notifications to the registered devices. If you have not registered your device on Skygear, please read the guide on device registration.
You can send Push Notification to all devices belongs to your selected users.
Sending push notification to devices
You can send Push Notifications to selected devices by give deviceId
s.
Sending push notification from cloud code
To send push notifications through cloud code, please refer to the Cloud Code Guide: Push Notifications.
Unregistering device
When a device is registered, it is associated with the authenticated user. Therefore it is necessary to unregister the device when the user is no longer associated with the device, for example when the user logs out.