Query Subscriptions
Skygear make it easy for you to subscribe to changes on the Database for real-time update. For example, you can create a query of all photos uploaded by a user Ben, and when the result set of query updated (for example a new photo was uploaded, or a photo uploaded by the user is deleted), your app will receive a notification.
Creating a subscription requires your application to register the current device on remote server. This is required for subscription to notify the client that a subscription is triggered.
When a subscription is triggered, remote server notifies the client through
the publish-subscribe (pubsub) mechanism. It is also recommended that your
application requests a remote notification through the
-registerForRemoteNotifications
. When a device token is available for
a device, the remote server also send a remote notification through Apple Push
Notification Service.
Having registered a device, your application should create a subscription by
specifying a query. The container will associate the device to the subscription
when you call the -saveSubscription:completionHandler:
on the database.
Registering device
Please refer to Push Notification - Registering device section to register the device first.
After you have registered device, you can then create a subscription.
In the register device callback, you should then add the subscriptions.
Register for push notifications
Adding subscription
Implementing SKYContainerDelegate
to receive notification
In Objective-C, add protocol declaration in AppDelegate
.
@interface AppDelegate : UIResponder <UIApplicationDelegate, SKYContainerDelegate>
In Swift, you should add an extension to the end of AppDelegate
.
extension AppDelegate: SKYContainerDelegate {
}
Note: An compiler error AppDelegate does not conform to protocol SKYContainerDelegate
may occur. Just ignore it. The error will be solved after adding the delegate method.
Implement the delegate method
Set AppDelegate
as container's delegate