Sundeep Saluja
Sundeep Saluja

Reputation: 1249

GCM (Google Cloud Messaging) for iOS apps

I am working on an iOS app, in which my client is asking for implementing GCM (Google Cloud Messaging) on iOS platform. I need to be sure if it can be done on iOS. As we use APNS for Push Notifications in iOS. Can anyone suggest me about this.

Thanks In Advance.

Upvotes: 1

Views: 1556

Answers (2)

abhimuralidharan
abhimuralidharan

Reputation: 5939

Its a late answer.But I just started working on GCM on iOS.SO I thought to answer this question as it might help someone. The following flow chart gives a brief idea on GCM.enter image description here

GCM can can be used to send updates to a single registrationID,a group to registrationIDs,or we can register a topic in the GCM server and we can send updates to all the devices subscribed to that particular topic.

Just follow the steps and you will find GCM integration easy.

STEP 1: Do watch this video completely : https://www.youtube.com/watch?v=gJatfdattno This gives the basic idea on how GCM works.

STEP 2 Goto this link: https://developers.google.com/cloud-messaging/ios/client

This shows clearly how you should configure the project.The main and important part is properly configuring the GCM config file.

You just have to upload apns certificate (developer and production) and get the gcm config file and add it to your project (drag and drop to your project navigation pane).

The following code which you should call in the didFinishLaunchingWithOptions will automatically fetch the _gcmSenderID from the config file.

_gcmSenderID = [[[GGLContext sharedInstance] configuration] gcmSenderID];

Another important part is properly setting the kGGLInstanceIDAPNSServerTypeSandboxOption to yes or no in didRegisterForRemoteNotificationsWithDeviceToken depending on which environment you are using the code(development or production).ie; kGGLInstanceIDAPNSServerTypeSandboxOption key should be YES if you are using it for testing.

Here is a sample quick start project for you to start with.(both swift and objective-C).Everything is well explained in this sample app. Let me know if you have any doubts.

Regarding actual communication, as long as the application is in the background on an iOS device, GCM uses APNS to send messages, the application behaving similarly as using Apple’s notification system. But when the app is active, GCM communicates directly with the app . The data payload and notification payload are both applicable on iOS & Android. On iOS the difference is that notification payload is sent through APNS while data payload is sent through GCM's own connection which is only there when app is in foreground.

Upvotes: 2

iDeveloper
iDeveloper

Reputation: 627

Please check this link it contains all steps to integrate GCM in iOS and requirement is you need to set up CocoaPods dependencies.

https://developers.google.com/cloud-messaging/ios/start

https://developers.google.com/cloud-messaging/ios/client

Upvotes: 3

Related Questions