+ All Categories
Home > Technology > Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

Date post: 21-Jan-2018
Category:
Upload: cumulations-technologies
View: 983 times
Download: 0 times
Share this document with a friend
21
Push Notification Using Firebase Cloud Messaging
Transcript
Page 1: Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

Push NotificationUsingFirebase Cloud Messaging

Page 2: Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

Topics

Push Notification

FCM

FCM implementationApplication/Client side

AndroidiOS

Server side

Page 3: Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

Push Notification

Push Notification is an message which pop up in the device. When the Application is Foreground or background.

Page 4: Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

FCMFCM is cross platform Messaging solution for reliably deliver message withno cost.

FCM Formerly known as GCM.

It is supported For Android, iOS and Web platforms.

Page 5: Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

Implementation in Android

Create a Firebase project for Application in the Firebase consoleFetch the SenderId and Server key

Application/Client Side Implementation

Add FCM Library in Project

dependencies {

compile 'com.google.firebase:firebase-messaging:+'

}

Fetch FCM client token and send to App server

FirebaseInstanceId.getInstance().getToken();

Page 6: Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

Implementation in AndroidImplement a service to handle Notification.

Class MyFirebaseMessagingService extends FirebaseMessagingService

{

onMessageReceived(RemoteMessage remoteMessage)

}

Notification Json format{

noification:{

title:

text:

},

Data:{

//custom key value pair

}

}

Page 7: Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

Application/Client side ImplementationImplementation in IOS

Requirement.

Steps for enabling push notification in iOS app.

Steps for enabling fcm in iOS app.

Notification handling.

Page 8: Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

Requirement

● Developer Id

● Mac OS

● Xcode 7 > (For fcm implementation)

● iOS device

Implementation in iOS

Page 9: Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

Steps for enabling push notification in iOS

● Enable push notification in app capabilities

● Setting APNs

○ Create ssl certificate using apple id

○ Create provisioning profile

○ And download and install it

○ And export that installed certificate to get p12

Implementation in IOS

Page 10: Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

For Fcm

● Import fcm using pod

● Download plist file

● Copy plist file to project

Implementation in IOS

Page 11: Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

● Register for remote notification

● Access registered token

● Monitor the token refresh

Steps for enabling push notification in iOS

Implementation in iOS

Page 12: Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

Handling and Types

Notification type

Remote notification

From server need notification token and pem file

Need fcm registration token with fcm

Local notification

Can be scheduled

Example- alarm

Implementation in iOS

Page 13: Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

Workflow

Implementation in iOS

Page 14: Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

Components

Requirement

Protocol and Method

Format

Server Side Implementation

Page 15: Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

● Components○ FCM connection servers: provided by Google. These servers take

messages from an app server and send them to a client app running on a device

○ App server: Sends notifications to the client app via FCM connection servers

Server Side Implementation

Page 16: Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

● Requirement○ End point: https://fcm.googleapis.com/fcm/send○ Server Key: AAAA3NfOkRw:APA91bE5d-p2a4uP1ah-

EysCnUpLjS9px3Luy-mj-7qclUIRW-i18gQHvvw7-mhFuSoZTI3TVrwbi-Q8UHq2K--6IxDJ4UGiKzATRBwf1soBb6GNcJ6sEHrC5OeUegJfNhzIlh-i46X_LP6Hh48AxZhJePQ1gw_ZSg

○ Registered Ids: ctin8xiuslQ:APA91bEX4-YjyqmfNozCd2qYEWxDVU9O1j5eKI8Ez4pWzF-ytIAyExGtb02G-wHfPToh1dYfmkDJdsJWWnOu1bgsyPQqbIntatBMULP_20OdTSVw1PxTgEbS5qoniwfM6H3jyTpQecBq

Server Side Implementation

Page 17: Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

● Protocol○ There are two protocols available: HTTP and XMPP○ The difference b/w HTTP and XMPP messaging is as follows:

■ Upstream/Downstream messages● HTTP: supports only downstream up to 4kb of data● XMPP: supports both up to 4kb of data

■ Messaging● HTTP: synchronous● XMPP: asynchronous, the XMPP connection server sends acknowledgment or failure

notifications (in the form of special ACK and NACK JSON-encoded XMPP messages) ■ JSON

● HTTP: supported● XMPP: supported (JSON message is encapsulated in XMPP messages)

■ Plain Text● HTTP: supported● XMPP: not supported

■ Multicast downstream send to multiple registration tokens● HTTP: supported● XMPP: not supported

● App server makes a POST (HTTP) request to the FCM connection server (curl is used for the same in php)

Server Side Implementation

Page 18: Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

● Request Format (HTTP) - Downstream message○ header must contain following keys will appripriate values:

■ Authorization: key=SERVER_KEY■ Content-Type: application/json (JSON) or application/x-www-form-urlencoded;charset=UTF-8 (plain text)

If content type is not provided the format will be assumed to be plain text○ Body must contain the following:

■ registration_ids (array)/to (string) - device registration tokens■ notification (object) - predefined, user-visible key-value pairs of the notification payload■ data (object) - custom key-value pairs of message payload

● Response Format (HTTP) - Downstream message○ Status: 200 on success/ non 200 status (4xx, 5xx) on failure○ Body

■ multicast_id - Unique ID (number) identifying the multicast message■ success - Number of messages that were processed without an error■ failure - Number of messages that could not be processed■ canonical_ids - Number of results that contain a canonical registration token■ results (array of objects)

● message_id - unique ID for each successfully processed message● registration_id - canonical registration token for the client app to which the message was processed

and sent to● error - error that occurred when processing the message for the recipient

Server Side Implementation

Page 19: Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

CURL Request Code:

Server Side Implementation

Page 20: Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

Response:

Server Side Implementation

Page 21: Push Notification for Android, iOS & Sever Side Using Firebase Cloud Messaging

Thank You


Recommended