Skip to main content

FCM Notification in android and IOS App

Free Teachnology provide free #PHP,#MySql,#Javascript,#jQuery,#API integration,#Payment gateway integration,#Social Media login

Firebase Cloud Messaging

Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages at no cost.

Using FCM, you can notify a client app that new email or other data is available to sync. You can send notification messages to drive user re-engagement and retention. For use cases such as instant messaging, a message can transfer a payload of up to 4KB to a client app

IOS Setup link :
https://firebase.google.com/docs/cloud-messaging/ios/client

Andriod Link :
https://firebase.google.com/docs/cloud-messaging/android/client

Web Link :
https://firebase.google.com/docs/cloud-messaging/js/client



Firebase Cloud Messaging (FCM) is a cross-platform messaging solution that lets you reliably deliver messages at no cost.

How does it work?
Firebase Cloud Messaging architecture diagram
An FCM implementation includes two main components for sending and receiving:

A trusted environment such as Cloud Functions for Firebase or an app server on which to build, target, and send messages.
An iOS, Android, or web (JavaScript) client app that receives messages.
You can send messages via the Admin SDK or the HTTP and XMPP APIs.

mplementation path
Set up the FCM SDK :
Set up Firebase and FCM on your app according to the setup instructions for your platform.

Develop your client app :
Add message handling, topic subscription logic, or other optional features to your client app. During the development, you can easily send test messages from the Notifications composer.

Develop your app server :
Decide whether you want to use the Admin SDK or one of the server protocols to create your sending logic—logic to authenticate, build sendrequests, handle responses, and so on. Then build out the logic in your trusted environment. Note that if you want to use upstream messaging from your client applications, you must use XMPP, and that Cloud Functions does not support the persistent connection required by XMPP.

Andriod Notification :
Set Up a Firebase Cloud Messaging Client App on Android

To write your Firebase Cloud Messaging Android client app, use the FirebaseMessaging API and Android Studio 1.4 or higher with Gradle. The instructions in this page assume that you have completed the steps for adding Firebase to your Android project.

FCM clients require devices running Android 4.0 or higher that also have the Google Play Store app installed, or an emulator running Android 4.0 with Google APIs. Note that you are not limited to deploying your Android apps through Google Play Store.

Set up Firebase and the FCM SDK
If you haven't already, add Firebase to your Android project.

In Android Studio, add the FCM dependency to your app-level build.gradle file:

implementation 'com.google.firebase:firebase-messaging:17.0.0'

Andriod app FCM notification :


$msg='hi how are you';
$kye="xxxxxxxxxxxxxxxxxxx";
$token="xxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$res = array();
$res['data']['title'] = "xxxxxx";
$res['data']['is_background'] = "xxxxxx";
$res['data']['message'] = "" . $msg . "";
$res['data']['payload'] = "payload";
$res['data']['timestamp'] = date('Y-m-d H');
$res['data']['icon'] = "ic_launcher";
$res['data']['color'] = "#374a96";
$res['data']['click_action'] = "action_tag";
$fields = array(
'to' => $token,
'data' => $res,
);
$url = 'https://fcm.googleapis.com/fcm/send';
$headers = array(
'Authorization: key=$kye',
'Content-Type: application/json'
);
// Open connection
$ch = curl_init();
// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
// Disabling SSL Certificate support temporarly
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
// Execute post
$result = curl_exec($ch);





Please follow following link to implemetation:
https://firebase.google.com/docs/cloud-messaging/android/client


Setting Up a Firebase Cloud Messaging Client App on iOS :

For iOS client apps, you can implement Firebase Cloud Messaging in two complementary ways:

Receive basic push messages up to 4KB over the Firebase Cloud Messaging APNs interface.

Send messages upstream and/or receive downstream data payloads up to 4KB in foregrounded apps.

To write your client code in Objective-C or Swift, we recommend that you use the FIRMessaging API. The quickstart example provides sample code for both languages.

Please follow following link of URL :
https://firebase.google.com/docs/cloud-messaging/ios/client

Add Firebase to your app
It's time to add Firebase to your app. To do this you'll need a Firebase project and a Firebase configuration file for your app.

To create a Firebase project:

Create a Firebase project in the Firebase console, if you don't already have one. Click Add project. If you already have an existing Google project associated with your mobile app, select it from the Project name drop down menu. Otherwise, enter a project name to create a new project.
Optional: Edit your Project ID. Your project is given a unique ID automatically, and it's used in publicly visible Firebase features such as database URLs and your Firebase Hosting subdomain. You can change it now if you want to use a specific subdomain.

Follow the remaining setup steps and click Create project (or Add Firebase if you're using an existing project) to begin provisioning resources for your project. This typically takes a few minutes. When the process completes, you'll be taken to the project overview.

IOS Notification in php using CURL call :


$msg='hi how are you';
$serverkey="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
//token generated from ios app
$token="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
$kye="xxxxxxxxxxxxxxxxxxx";
#API access key from Google API's Console
define( 'API_ACCESS_KEY', $serverkey );
$registrationIds = $token;
#prep the bundle
$msg = array
(
'body' => 'Body Of Notification',
'title' => 'Title Of Notification',
'icon' => 'myicon',/*Default Icon*/
'sound' => 'mySound'/*Default sound*/
);
$fields = array('to' => $registrationIds,'notification' => $msg);
$headers = array('Authorization: key=' . API_ACCESS_KEY,'Content-Type: application/json');
#Send Reponse To FireBase Server 
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://fcm.googleapis.com/fcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
#Echo Result Of FireBase Server
echo $result;


hope that you better understand above boostrap datepicker tutorial if you have any query please mail on : disuzajen@gmail.com

Comments

Popular posts from this blog

using PDO database connection add,update,delete,edit operation

PDO advantage : 1-Object Oriented 2-Bind parameters in statements (security) 3-Allows for prepared statements and rollback functionality (consistency) 4-Throws catcheable exceptions for better error handling (quality) 5-Exception mode; no need to check error state after each API call. It's best to tell PDO how you'd like the data to be fetched. You have the following options: 1-PDO::FETCH_ASSOC: returns an array indexed by column name. 2-PDO::FETCH_BOTH: (default):returns an array indexed by both column name and number. 3-PDO::FETCH_BOUND:Assigns the values of your columns to the variables set with the ->bindColumn() method. 4-PDO::FETCH_CLASS: Assigns the values of your columns to properties of the named class. It will create the properties if matching properties do not exist. 5-PDO::FETCH_INTO:Updates an existing instance of the named class. 6-PDO::FETCH_LAZY: Combines. 7-PDO::FETCH_BOTH/PDO:FETCH_OBJ, creating the object variable names as t...

Profile Share Fixing the Thumbnail Image, Title and Description for Shared Links

Profile Share Fixing the Thumbnail Image, Title and Description for Shared Links user want to share any information then use following code  and read step by step Profile Share Fixing the Thumbnail Image, Title and Description for Shared Links if you want share profile on following social link : 1-Facebook 2-twitter.com 3-LinkedIn 4-google +, Code link : https://drive.google.com/open?id=1IzTZZh_0euDqFSHL_vPRiQePlNTw3h-q Demo link : http://freeteachnology.hol.es/socialshare/ To modify a page's thumbnail image, description, and additional metadata for these services, you can provide meta tags in the HTML code of the page.Implementing Open Graph Meta Tags You can implement meta tags in a number of ways. In content management systems might  be allow you to modify a page's meta tags , then use following code in meta section of your project code, <link href="bootstrap.min.css" rel="stylesheet"> <link href="bootstrap-tour.m...

GUID for globally unique identifier

How to create GUID in php 1-guid stands for globally unique identifier generally used to create random unique strings in php, create access token in php 2-Mostly use of GUID for generating access token, generate unique id, generating unique string in php. Using this article how to create guide in php you can create a random string for any use to keep unique 3-GUID consists of alphanumeric characters only and is grouped in five groups separated by hyphens as seen in this example: 3F2504E0-4F89-11D3-9A0C-0305E82C3301 Eg:- <?php /** * Generate Globally Unique Identifier (GUID) * E.g. 2EF40F5A-ADE8-5AE3-2491-85CA5CBD6EA7 * * @param boolean $include_braces Set to true if the final guid needs * to be wrapped in curly braces * @return string */ function generateGuid($include_braces = false) { if (function_exists('com_create_guid')) { if ($include_braces === true) { return com_create_guid(); } else { return substr(com_cr...