com.stackmob.sdkapi
Interface PushService


public interface PushService

Provides access to the StackMob push notification service, allowing the creation of push notifications directly from a custom code method.


Method Summary
 void broadcastPush(int badge, String sound, String alert)
          Broadcast a push notification to all devices running this app.
 Map<String,Long> getExpiredTokens(boolean clear)
          Get the tokens, which have been reported as expired by Apple's feedback service
 Map<String,String> getTokensForUsers(List<String> users)
          Finds the device push tokens for the given user list.
 void registerToken(String username, String token)
          Assign a push token to the specified user.
 void removeToken(String token)
          Removes the token from the list of registered tokens.
 void sendPush(List<String> tokens, int badge, String sound, String alert)
          Send a push notification to all devices identified by the tokens provided.
 void sendPush(List<String> recipients, int badge, String sound, String alert, boolean recipientsAreTokens)
          Send a push notification to all devices identified by the recipients list.
 

Method Detail

sendPush

void sendPush(List<String> tokens,
              int badge,
              String sound,
              String alert)
              throws PushServiceException
Send a push notification to all devices identified by the tokens provided. This is a shorthand for sendPush(tokens, badge, sound, alert, true)

Parameters:
tokens - the device tokens to which the push notification should be sent
badge - the badge for the push notification; specifies the number to be displayed with the app icon
sound - the sound to be played by the devices
alert - the text of the alert to be displayed by the devices
Throws:
PushServiceException - if an error occurs

sendPush

void sendPush(List<String> recipients,
              int badge,
              String sound,
              String alert,
              boolean recipientsAreTokens)
              throws PushServiceException
Send a push notification to all devices identified by the recipients list. The meaning of the entries in the recipients list is controlled by the recipientsAreTokens parameter. If true, the recipients list is considered to consist of device tokens. If false, the recipients list will be considered to be user IDs. In either case, tokens need to be registered via the registerToken(String, String) call, before they can be used.

Parameters:
recipients - the device tokens to which the push notification should be sent
badge - the badge for the push notification; specifies the number to be displayed with the app icon
sound - the sound to be played by the devices
alert - the text of the alert to be displayed by the devices
recipientsAreTokens - the type of entries in the recipients list. True if specifying tokens; false for users.
Throws:
PushServiceException - if an error occurs

broadcastPush

void broadcastPush(int badge,
                   String sound,
                   String alert)
                   throws PushServiceException
Broadcast a push notification to all devices running this app.

Parameters:
badge - the badge for the push notification; specifies the number to be displayed with the app icon
sound - the sound to be played by the devices
alert - the text of the alert to be displayed by the devices
Throws:
PushServiceException - if an error occurs

getExpiredTokens

Map<String,Long> getExpiredTokens(boolean clear)
                                  throws DatastoreException
Get the tokens, which have been reported as expired by Apple's feedback service

Parameters:
clear - if true, the set of expired tokens will be cleared after the call. if false, the current token set will be retained on the server
Returns:
A list of expired tokens, represented as a Map, where the token is the key, and the value is the expiration time, represented as milliseconds since January 1, 1970 UTC
Throws:
DatastoreException - if an error occurs

registerToken

void registerToken(String username,
                   String token)
                   throws DatastoreException
Assign a push token to the specified user. After a token is registered, it may be used to push messages to the user. If the username is null, or an empty string, the token will be registered without a username.

Parameters:
username - a username to associate with the specified token
token - iOS device token
Throws:
DatastoreException - if an error occurs

getTokensForUsers

Map<String,String> getTokensForUsers(List<String> users)
                                     throws DatastoreException
Finds the device push tokens for the given user list. Will not return the tokens, which were marked as expired by the feedback service. Use getExpiredTokens(boolean) to get the expired tokens.

Parameters:
users - list of user IDs
Returns:
a map of user IDs to push tokens. If no token is registered for a user, then the user ID will not be included in the returned map
Throws:
DatastoreException - if an error occurs

removeToken

void removeToken(String token)
                 throws DatastoreException
Removes the token from the list of registered tokens.

Parameters:
token - token to be removed
Throws:
DatastoreException - if an error occurs


Copyright © 2011 StackMob. All Rights Reserved.