GGLContext(CloudMessaging) Category

GGLContext(CloudMessaging) Category Reference

Overview

This category extends GGLContext with Google Cloud Messaging.

To integrate Google Cloud Messaging import import GGLContext+CloudMessaging.h.

[GGLContext sharedInstance].gcmSenderID should be ready to use after calling -[[GGLContext sharedInstance] configureWithError:]. Functions -[fetchInstanceIDTokenWithAPNSToken:handler:], -[connectToGCMWithHandler:] and -[disconnectFromGCM] can be then used.

See also
GGLContext

Instance Method Summary

(void) - fetchInstanceIDTokenWithAPNSToken:handler:
 Gets an InstanceID token scoped for GCM using the gcmSenderID. More...
 
(void) - startGCMService
 Start the Google Cloud Messaging service after setting the appropriate properties. More...
 
(void) - startGCMServiceWithConfig:
 Start the Google Cloud Messaging service with the given config. More...
 
(void) - stopGCMService
 Stop the Google Cloud Messaging service. More...
 
(void) - connectToGCMWithHandler:
 Creates a connection to Google Cloud Messaging, which will be used to receive push and topic notifications when the app is in the foreground, and to send upstream messages. More...
 
(void) - disconnectFromGCM
 Closes an existing connection to GCM, if present. More...
 
(void) - subscribeToTopic:withHandler:
 Subscribe to a GCM pubsub topic. More...
 
(void) - unsubscribeFromTopic:withHandler:
 Unsubscribe the client from a GCM pubsub topic. More...
 

Properties

NSString * gcmSenderID
 The Project Number used to configure Google Cloud Messaging. More...
 
NSString * registrationToken
 Provides a token identifying this instance of the app, which can be used by a remote server to push messages to this client. More...
 

Method Detail

- (void) fetchInstanceIDTokenWithAPNSToken: (NSData *)  apnsToken
handler: (GGLInstanceIDTokenHandler)  handler 

Gets an InstanceID token scoped for GCM using the gcmSenderID.

This allows the app to receive push notifications using Apple Push Notification Service (APNS).

This method should be called on app launch after -[[GGLContext sharedInstance] configureWithError:] has completed.

Parameters
apnsTokenThe APNS token returned from UIApplication's didRegisterForRemoteNotificationsWithDeviceToken method.
handlerThe handler to be invoked once the InstanceID token has been successfully fetched.

Extends class GGLContext.

- (void) startGCMService

Start the Google Cloud Messaging service after setting the appropriate properties.

Call this only once during the lifetime of the app before you start using Google Cloud Messaging.

Uses the default config to start the service. The log level is set to DEBUG and it does not provide an implementation for GCMReceiverDelegate.

Extends class GGLContext.

- (void) startGCMServiceWithConfig: (GCMConfig *)  config

Start the Google Cloud Messaging service with the given config.

Call this only once during the lifetime of the app before you start using Google Cloud Messaging.

Parameters
configThe GCMConfig used to start the service.

Extends class GGLContext.

- (void) stopGCMService

Stop the Google Cloud Messaging service.

Stop all the operations associated with it and clear any objects or data associated with it. Call this only once during the lifetime of your app when you don't want to use Google Cloud Messaging anymore.

Extends class GGLContext.

- (void) connectToGCMWithHandler: (GCMServiceConnectCompletion)  handler

Creates a connection to Google Cloud Messaging, which will be used to receive push and topic notifications when the app is in the foreground, and to send upstream messages.

It will also be used to send ACKS and other messages based on the GCM protocol.

This method should be called on app launch after -[[GGLContext sharedInstance] configureWithError:], in -[fetchInstanceIDTokenWithAPNSToken:handler:]'s completion handler. As well as each time the app enters the foreground.

Parameters
handlerThe handler to be invoked once the GCM connection has been established. If a connection cannot be established, this will be invoked with an error and the process will retry using an exponential backoff.

Extends class GGLContext.

- (void) disconnectFromGCM

Closes an existing connection to GCM, if present.

Disables connection retries if the connection has not yet been established.

This method should be called each time the app enters the background or terminates.

Extends class GGLContext.

- (void) subscribeToTopic: (NSString *)  topic
withHandler: (GCMPubSubCompletion)  handler 

Subscribe to a GCM pubsub topic.

The topic name should match the regex "/topics/[a-zA-Z0-9-_.~%]{1,900}".

Parameters
topicThe topic to subscribe to.
handlerThe completion handler to invoke when the subscription request finishes.

Extends class GGLContext.

- (void) unsubscribeFromTopic: (NSString *)  topic
withHandler: (GCMPubSubCompletion)  handler 

Unsubscribe the client from a GCM pubsub topic.

The topic name should match the regex "/topics/[a-zA-Z0-9-_.~%]{1,900}".

Parameters
topicThe topic to unsubscribe from.
handlerThe completion handler to invoke when the unsubsribe request finishes.

Extends class GGLContext.

Property Documentation

- (NSString*) gcmSenderID
readnonatomicstrong

The Project Number used to configure Google Cloud Messaging.

It will be ready to use once -[[GGLContext sharedInstance] configureWithError:] is called.

See also
GGLContext configure

Extends class GGLContext.

- (NSString*) registrationToken
readnonatomicstrong

Provides a token identifying this instance of the app, which can be used by a remote server to push messages to this client.

It will only be ready to use after -[[GGLContext sharedInstance] configureWithError:] has been called and -[fetchInstanceIDTokenWithAPNSToken:handler:]'s completion handler has been invoked.

See also
GGLContext configure

Extends class GGLContext.