Manage Push Channel tokens and notifications. More...
#import <BlackBerryDynamics/GD/GDPush.h>
The Push Channel framework is a BlackBerry Dynamics feature used to receive notifications from an application server.
Note that the BlackBerry Dynamics Push Channel feature is not part of the native iOS notification feature set.
Use of the Push Channel feature in the application is dependent on:
Push Channel data communication doesn't go via the proxy specified in the native settings of the device or computer on which the application is running, if any.
Push Channels are established by the BlackBerry Dynamics application, then used by the application server when needed. The sequence of events is as follows.
The BlackBerry Dynamics platform keeps data communications between the application and server alive while the application is waiting for a Push Channel notification. This is achieved by sending "heartbeat" messages at an interval that is dynamically optimized for battery and network performance.
Ping Failure is an optional feature of the Push Channel framework. The application server can register a ping address after receiving the Push Channel token from the mobile application.
If the application server registers a ping address, then it will be periodically checked ("pinged") by the BlackBerry Dynamics Network Operation Center (NOC). If the server does not respond to a ping, then the NOC notifies the application that requested the corresponding Push Channel.
The purpose of this feature is to support servers that lose the Push Channel token when they are restarted.
See the Push Channel Back-End API for details of Ping Failure registration.
The Push Channel programming interface is asynchronous and state-based. The application code creates a Push Channel object for each channel it will use, typically one per application server. When a channel changes state, or a channel event occurs, the BlackBerry Dynamics runtime notifies the application.
To notify the application, the runtime posts an NSNotification
.
For all NSNotification
instances that are Push Channel notifications:
userInfo
, depends on the event type. The following values are used as keys.
Push Channel state changes can also be detected by key-value observing (KVO) of the state property.
The availability of functions in the Push Channel programming interface, and what actions take place, are detailed below, and summarized in the following table. The table also summarizes which notifications are expected in each state.
State | Functions and actions | Expected notifications See Push Channel Constants |
---|---|---|
Prepared | Application can call connect : state becomes Connecting | None |
Connecting | BlackBerry Dynamics runtime requests a new channel from the proxy infrastructure | GDPushChannelErrorNotification : new state is FailedGDPushChannelOpenedNotification : new state is Open |
Open | Application can call disconnect : state becomes Disconnecting | GDPushChannelMessageNotification : no state changeGDPushChannelPingFailedNotification : no state changeGDPushChannelClosedNotification : new state is Disconnected |
Disconnecting | BlackBerry Dynamics Runtime requests the proxy infrastructure to close the channel | GDPushChannelMessageNotification : no state changeGDPushChannelPingFailedNotification : no state changeGDPushChannelClosedNotification : new state is Disconnected |
Disconnected | Application can call connect : state becomes Connecting | None |
Failed | Application can call connect : state becomes Connecting | None |
The transitions in the above table are also shown in this diagram.
Note that an individual Push Channel might or might not be closed when the overall Push Channel service becomes unavailable.
The capabilities of the BlackBerry Dynamics Push Channel are different to the capabilities of the native Apple Push Notification Service (APNS) in the following ways.
Only native notifications can be received when the application is in background. This might change in a future release of iOS.
In principle, native notifications alert the user, not the application. Having been alerted, the user may choose to open the application. BlackBerry Dynamics Push Channel messages alert the application, which in turn may alert the user.
BlackBerry Dynamics Push Channel messages can include a "payload" of application data from the server. The application data is conveyed by the proxy infrastructure from the server to the application.
Native notifications may be received whenever the device has a connection to APNS. BlackBerry Dynamics Push Channel messages may be received whenever the application has a connection to the BlackBerry Dynamics infrastructure.
Every Push Channel must have an identifier. Identifiers must be unique within an application. A Push Channel identifier is a text string set by the application code. Note that Push Channel identifiers aren't the same as Push Channel tokens. Token values are set by the BlackBerry Dynamics infrastructure and runtime.
The following convention represents best practice for Push Channel identifiers.
A Push Channel identifier should be composed of a domain followed by a module name and an optional purpose. The parts are separated by full stops (periods). The following examples illustrate the convention.
Example: com.example.mobile-life.email
Example: com.example.dashboard
The rules for identifier part values are as follows.
The following code snippets illustrate some common tasks.
The following snippet shows a Push Channel being created and opened after checking that the service is available.
The above snippet shows the following taking place:
The attempt is asynchronous. The associated GDPushChannelOpenedNotification
notification would be received if and when the attempt is succesful (not shown).
The above snippet shows: Request to disconnect the Push Channel.
The request is asynchronous. The associated GDPushChannelClosedNotification
notification would be received when the closure is finalized (not shown).
The following code snippets illustrate some common tasks.
The following snippet shows a simple handler for when a Push Channel opens.
The above snippet shows the following taking place:
sendPushToken
function in the application is called.The sendPushToken
function, which would be written by the application developer, would send the token to the application server. This could use a socket, an HTTP request, or another means of communication. From the Push Channel point of view, this is an out-of-band communication.
The server will use the token to address Push Channel notification messages back to the application. These would be received by the application's Push Channel event handler code.
The above snippet shows the following taking place when a Push Channel message is received:
processPush
function in the application is called and passed the content of the message.The processPush
function, which would be written by the application developer, could initiate any of the following actions:
The above snippet shows a simple channel closure handler. The following takes place when the Push Channel is closed:
discardPushToken
function is called. The token of the closed channel is passed as a parameter.The discardPushToken
function would delete the application's copy of the token, possibly after checking that it matches the previous stored token.
The function could also initiate connection of a new Push Channel, which would have a new token. See connect .
The above snippet shows a simple Error
handler.
The handler logs the error code to the system monitor, flags the channel's state as not connected, records the error code in the application, then calls the application discardPushToken
function.
The discardPushToken
function could do any of the following:
See under Ping Failure in the Push Channel Back-End API for an explanation of the Ping Failure feature.
The above snippet shows a simple Ping Failure handler.
The handler logs the error code to the system monitor, then calls the application resendPushToken
function if the token was lost.
The resendPushToken
function, which would be written by the application developer, would send the application's stored token to the application server. This could use a socket, an HTTP request, or another means of communication. From the Push Channel point of view, this is an out-of-band communication.
The resendPushToken
function should expect that the server is not immediately available, perhaps employing a retry policy.
Instance Methods | |
(instancetype) | - initWithIdentifier: |
Constructor that prepares a new Push Channel. More... | |
(void) | - connect |
Connect Push Channel. More... | |
(void) | - disconnect |
Disconnect Push Channel. More... | |
Properties | |
GDPushChannelState | state |
Push Channel state. More... | |
- (instancetype) initWithIdentifier: | (NSString *) | pushChannelIdentifier |
Call this function to construct a new Push Channel object. This function does not initiate data communication. See connect .
pushChannelIdentifier | NSString containing the identifier for this Push Channel, see under Push Channel Identifiers, above. |
- (void) connect |
Call this function to open the Push Channel connection. This function can only be called when the channel isn't open.
This function causes a request for a Push Channel to be sent to the BlackBerry Dynamics Network Operation Center (NOC). The NOC will create the channel, and issue a Push Channel token, which can then be used to identify the channel.
The connection attempt is asynchronous. An NSNotification
with a user information dictionary, userInfo
, will be posted to notify the application of the result. If the attempt succeeds, the notification name will be GDPushChannelOpenedNotification
, and the userInfo
will contain a GDPushChannelTokenKey
entry of NSString
type with the token as its value and if applicable a GDPushChannelHostKey
entry of NSString
type with push service host name. If the attempt fails, the notification name will be GDPushChannelErrorNotification
, and the userInfo
will contain a GDPushChannelErrorKey
entry holding an NSInteger
value.
- (void) disconnect |
Call this function to initiate permanent disconnection of the Push Channel. This function can only be called when the channel is open.
This function causes a request for Push Channel termination to be sent to the BlackBerry Dynamics Network Operation Center (NOC). The NOC will delete the channel, and invalidate the Push Channel token that was issued when the channel was initially opened, see connect .
Disconnection is asynchronous. When disconnection is complete, an NSNotification
is posted to notify the application. The notification name will be GDPushChannelClosedNotification
.
Note. This function is for permanent closure of the channel. Transient suspension of Push Channel notifications may be more easily accomplished out-of-band, by direct communication with the application server.
If the connection with the NOC is open and operating, and the application server that was sent the token registered for isDisconnected
, then a disconnect notification will be sent to the application server, by the NOC. See the Push Channel Back-End API.
|
readnonatomicassign |
The BlackBerry Dynamics runtime sets this property to one of the GDPushChannelState values to represent the state of the channel.
This property is compatible with key-value observing (KVO).