1560829098
The comprehensive step by step tutorial on receiving a push notification on Mobile App using Ionic 4 and Firebase Cloud Messaging (FCM). We will use Ionic 4 Cordova native FCM plugin for receiving a push notification and using Firebase API for sending push notification from the Postman.
The following tools, frameworks, and modules are required for this tutorial:
Before going to the main steps, we assume that you have to install Node.js. Next, upgrade or install new Ionic 4 CLI by open the terminal or Node command line then type this command.
sudo npm install -g ionic
You will get the latest Ionic CLI in your terminal or command line. Check the version by type this command.
ionic --version
4.10.3
1. Setup and Configure Google Firebase Cloud Messaging
Open your browser then go to Google Firebase Console then login using your Google account.
Next, click on the Add Project button then fill the Project Name with Ionic 4 FCM
and check the terms then click Create Project button.
After clicking the continue button you will redirect to the Project Dashboard page. Click the Gear Button on the right of Project Overview then click Project Settings. Click the Cloud Messaging tab the write down the Server Key and Sender ID for next usage in the API and Ionic 4 App. Next, back to the General tab then click the Android icon in your Apps to add Android App.
Fill the required fields in the form as above then click Register App button. Next, download the google-services.json
that will use in the Ionic 4 app later. Click next after download, you can skip Add Firebase SDK by click again Next button. You can skip step 4 if there’s no App creating on running yet.
2. Create a new Ionic 4 App
To create a new Ionic 4 App, type this command in your terminal.
ionic start ionic4-push blank --type=angular
If you see this question, just type N
for because we will installing or adding Cordova later.
Install the free Ionic Appflow SDK and connect your app? (Y/n) N
Next, go to the newly created app folder.
cd ./ionic4-push
As usual, run the Ionic 4 App for the first time, but before run as lab
mode, type this command to install @ionic/lab
.
npm install --save-dev @ionic/lab
ionic serve -l
Now, open the browser and you will the Ionic 4 App with the iOS, Android, or Windows view. If you see a normal Ionic 4 blank application, that’s mean you ready to go to the next steps.
3. Add Ionic 4 Cordova Native FCM Plugin
To install Ionic 4 Cordova Native Firebase Message Plugin, type this command.
ionic cordova plugin add cordova-plugin-fcm-with-dependecy-updated
npm install @ionic-native/fcm
Next, open and edit src/app/app.module.ts
then add this import.
import { FCM } from '@ionic-native/fcm/ngx';
Add to @NgModule
providers.
providers: [
StatusBar,
SplashScreen,
FCM,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
Next, open and edit src/app/app.component.ts
then add this import.
import { FCM } from '@ionic-native/fcm/ngx';
import { Router } from '@angular/router';
Inject FCM and Router module to the constructor.
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private fcm: FCM,
private router: Router
) {
this.initializeApp();
}
Inside platform ready of initializeApp
function, add a function to get FCM token then print out to the browser console.
this.fcm.getToken().then(token => {
console.log(token);
});
Add this function to refresh the FCM token.
this.fcm.onTokenRefresh().subscribe(token => {
console.log(token);
});
Add this function to receive push notification from Firebase Cloud Messaging.
this.fcm.onNotification().subscribe(data => {
console.log(data);
if (data.wasTapped) {
console.log('Received in background');
this.router.navigate([data.landing_page, data.price]);
} else {
console.log('Received in foreground');
this.router.navigate([data.landing_page, data.price]);
}
});
Above example of receiving a push notification from FCM will redirect to the other page with params of data. For that, next, we have to add a new page by type this command.
ionic g page second
Next, modify src/app/app-routing.module.ts
then change the new page route.
const routes: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', loadChildren: './home/home.module#HomePageModule' },
{ path: 'second/:price', loadChildren: './second/second.module#SecondPageModule' },
];
Next, open and edit src/app/second/second.page.ts
then add this import.
import { ActivatedRoute } from '@angular/router';
Inject that module to the constructor.
constructor(private route: ActivatedRoute) { }
Add a variable for hold data from router parameters.
price: any = '';
Add this line to get data from the router parameters.
constructor(private route: ActivatedRoute) {
this.price = this.route.snapshot.params['price'];
}
Next, open and edit src/app/second/second.page.html
then replace all HTML tags with this.
<ion-header>
<ion-toolbar>
<ion-title>Second</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-card>
<ion-card-header>
<ion-card-title>Congratulation!</ion-card-title>
</ion-card-header>
<ion-card-content>
You get price from our sponsor:
<h2>{{price}}</h2>
</ion-card-content>
</ion-card>
</ion-content>
If you plan to send push notification to the group of topic, add this lines inside the platform ready.
this.fcm.subscribeToTopic('people');
To unsubscribe from topic, add this line.
this.fcm.unsubscribeFromTopic('marketing');
4. Run and Test Sending and Receiving Push Notification
Before running this Ionic 4 app, we have to copy the downloaded google-services.json
file to the root of the project. Type this command to add the Android platform.
ionic cordova platform add android
Next, copy the google-services.json
to the platform/android/
directory.
cp google-services.json platform/android/
Next, run the Ionic 4 App to the Android device by type this command.
ionic cordova run android
After the app running on the device, check the console from the Google Chrome by type this address chrome://inspect
then choose the inspect link. You should take to the browser inspector, just change to the console tab.
As you can see above, you can take and write down the FCM token for use by Postman. Next, open the Postman application from your computer. Change the method to POST and add this address [https://fcm.googleapis.com/fcm/send](https://fcm.googleapis.com/fcm/send "https://fcm.googleapis.com/fcm/send")
. On the headers, add this key Content-Type
with value application/json
and Authorization
with value key=YOUR_FIREBASE_KEY...
.
Next, add this JSON data to the RAW body.
{
"notification":{
"title":"Ionic 4 Notification",
"body":"This notification sent from POSTMAN using Firebase HTTP protocol",
"sound":"default",
"click_action":"FCM_PLUGIN_ACTIVITY",
"icon":"fcm_push_icon"
},
"data":{
"landing_page":"second",
"price":"$3,000.00"
},
"to":"eadego-nig0:APA91bEtKx9hv50lmQmfzl-bSDdsZyTQ4RkelInfzxrPcZjJaSgDmok3-WQKV5FBu9hrMrkRrcCmf3arkGSviGltg5CyC2F9x1J2m0W7U8PxJ3Zlh7-_tL6VcFdb76hbaLIdZ-dOK15r",
"priority":"high",
"restricted_package_name":""
}
If you want to send by topics recipients, change the value of to
to topics/people
. Next, click the send button and you should see this response.
{
"multicast_id": 7712395953543412819,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:1550632139317442%b73443ccb73443cc"
}
]
}
And you will see the notification in your Android device background screen.
If you tap on it, it will open the App and redirect to the second page with this view.
That it’s, the example of receiving push notification using Ionic 4 and Firebase Cloud Messaging. You can grab the full source code from our GitHub.
#ionic #firebase #angular
1572481618
Everything is working for me except for navigation.
It won’t navigate to the specified page when the app opens:
if (!firebase.apps.length) {
firebase.initializeApp(firebaseConfig);
}
this.platform.ready().then(() => {
const unsubscribe = firebase.auth().onAuthStateChanged( user => {
if (!user) {
this.router.navigateByUrl('login');
unsubscribe();
} else {
this.router.navigateByUrl('tabs');
unsubscribe();
}
});
this.statusBar.styleDefault();
this.splashScreen.hide();
this.getDeviceToken();
});
}
getDeviceToken() {
this.fcm.onNotification().subscribe(data => {
if (data.wasTapped) {
console.log("Received in background", data);
console.log("Tapped: " + JSON.stringify(data));
console.log("Received in background", data.page);
this.router.navigateByUrl('tabs/connections');
} else {
console.log("Received in foreground", data.wasTapped);
this.router.navigateByUrl('tabs/connections');
}
});
this.fcm.onTokenRefresh().subscribe(token => {
// Register your new token in your back-end if you want
this.fcmService.saveTokenToFirestore(token, this.loggedInUser.uid);
});
}
}```
1594162500
A multi-cloud approach is nothing but leveraging two or more cloud platforms for meeting the various business requirements of an enterprise. The multi-cloud IT environment incorporates different clouds from multiple vendors and negates the dependence on a single public cloud service provider. Thus enterprises can choose specific services from multiple public clouds and reap the benefits of each.
Given its affordability and agility, most enterprises opt for a multi-cloud approach in cloud computing now. A 2018 survey on the public cloud services market points out that 81% of the respondents use services from two or more providers. Subsequently, the cloud computing services market has reported incredible growth in recent times. The worldwide public cloud services market is all set to reach $500 billion in the next four years, according to IDC.
By choosing multi-cloud solutions strategically, enterprises can optimize the benefits of cloud computing and aim for some key competitive advantages. They can avoid the lengthy and cumbersome processes involved in buying, installing and testing high-priced systems. The IaaS and PaaS solutions have become a windfall for the enterprise’s budget as it does not incur huge up-front capital expenditure.
However, cost optimization is still a challenge while facilitating a multi-cloud environment and a large number of enterprises end up overpaying with or without realizing it. The below-mentioned tips would help you ensure the money is spent wisely on cloud computing services.
Most organizations tend to get wrong with simple things which turn out to be the root cause for needless spending and resource wastage. The first step to cost optimization in your cloud strategy is to identify underutilized resources that you have been paying for.
Enterprises often continue to pay for resources that have been purchased earlier but are no longer useful. Identifying such unused and unattached resources and deactivating it on a regular basis brings you one step closer to cost optimization. If needed, you can deploy automated cloud management tools that are largely helpful in providing the analytics needed to optimize the cloud spending and cut costs on an ongoing basis.
Another key cost optimization strategy is to identify the idle computing instances and consolidate them into fewer instances. An idle computing instance may require a CPU utilization level of 1-5%, but you may be billed by the service provider for 100% for the same instance.
Every enterprise will have such non-production instances that constitute unnecessary storage space and lead to overpaying. Re-evaluating your resource allocations regularly and removing unnecessary storage may help you save money significantly. Resource allocation is not only a matter of CPU and memory but also it is linked to the storage, network, and various other factors.
The key to efficient cost reduction in cloud computing technology lies in proactive monitoring. A comprehensive view of the cloud usage helps enterprises to monitor and minimize unnecessary spending. You can make use of various mechanisms for monitoring computing demand.
For instance, you can use a heatmap to understand the highs and lows in computing visually. This heat map indicates the start and stop times which in turn lead to reduced costs. You can also deploy automated tools that help organizations to schedule instances to start and stop. By following a heatmap, you can understand whether it is safe to shut down servers on holidays or weekends.
#cloud computing services #all #hybrid cloud #cloud #multi-cloud strategy #cloud spend #multi-cloud spending #multi cloud adoption #why multi cloud #multi cloud trends #multi cloud companies #multi cloud research #multi cloud market
1594166040
The moving of applications, databases and other business elements from the local server to the cloud server called cloud migration. This article will deal with migration techniques, requirement and the benefits of cloud migration.
In simple terms, moving from local to the public cloud server is called cloud migration. Gartner says 17.5% revenue growth as promised in cloud migration and also has a forecast for 2022 as shown in the following image.
#cloud computing services #cloud migration #all #cloud #cloud migration strategy #enterprise cloud migration strategy #business benefits of cloud migration #key benefits of cloud migration #benefits of cloud migration #types of cloud migration
1594631472
Entrepreneurs around the world want a top-notch mobile application for their business in both Android and iOS platforms. Most of them get stuck mid-way where they struggle to pick the best technology suitable for their business. From questions such as native mobile development or cross-platform development? Flutter or Ionic or React Native?. Each technology and development approach has its own Pros and Cons from which you will need to choose the right one for your business. If you think Ionic is the right cross-platform application development, here are a few pros and cons of Ionic development.
Being an open-source SDK for building Hybrid mobile applications in both Android and iOS platforms, Ionic is the best choice for building top of the line mobile applications. This Ionic framework is completely based on Apache Cordova and Angular. More precisely, Ionic is an npm module that requires the installation of Node JS to function.
One can build a full functioning mobile application in both platforms using their Javascript, HTML, and CSS knowledge without requiring the basics of Kotlin or Java. More than 5 Million mobile applications are built using this Ionic framework by leveraging its platform-specific UI elements, innumerable libraries, and more exciting features.
The applications that are built using the Ionic framework are cross-platform, web-based, and have access to native device’s APIs.
Ionic Applications are
For entrepreneurs and business owners, ionic development can be beneficial if they want to develop a mobile application in both platforms in a short period of time while comparing to native applications. Building native applications specifically for each platform can be time-consuming which can imply a delay in time to market and development cost of native applications are generally expensive.
#mobile app development #ionic 4 advantages #ionic 4 best practices #ionic 5 #ionic appflow #ionic capacitor pros and cons #ionic vs react native #react native pros and cons #what is ionic app development
1560829098
The comprehensive step by step tutorial on receiving a push notification on Mobile App using Ionic 4 and Firebase Cloud Messaging (FCM). We will use Ionic 4 Cordova native FCM plugin for receiving a push notification and using Firebase API for sending push notification from the Postman.
The following tools, frameworks, and modules are required for this tutorial:
Before going to the main steps, we assume that you have to install Node.js. Next, upgrade or install new Ionic 4 CLI by open the terminal or Node command line then type this command.
sudo npm install -g ionic
You will get the latest Ionic CLI in your terminal or command line. Check the version by type this command.
ionic --version
4.10.3
1. Setup and Configure Google Firebase Cloud Messaging
Open your browser then go to Google Firebase Console then login using your Google account.
Next, click on the Add Project button then fill the Project Name with Ionic 4 FCM
and check the terms then click Create Project button.
After clicking the continue button you will redirect to the Project Dashboard page. Click the Gear Button on the right of Project Overview then click Project Settings. Click the Cloud Messaging tab the write down the Server Key and Sender ID for next usage in the API and Ionic 4 App. Next, back to the General tab then click the Android icon in your Apps to add Android App.
Fill the required fields in the form as above then click Register App button. Next, download the google-services.json
that will use in the Ionic 4 app later. Click next after download, you can skip Add Firebase SDK by click again Next button. You can skip step 4 if there’s no App creating on running yet.
2. Create a new Ionic 4 App
To create a new Ionic 4 App, type this command in your terminal.
ionic start ionic4-push blank --type=angular
If you see this question, just type N
for because we will installing or adding Cordova later.
Install the free Ionic Appflow SDK and connect your app? (Y/n) N
Next, go to the newly created app folder.
cd ./ionic4-push
As usual, run the Ionic 4 App for the first time, but before run as lab
mode, type this command to install @ionic/lab
.
npm install --save-dev @ionic/lab
ionic serve -l
Now, open the browser and you will the Ionic 4 App with the iOS, Android, or Windows view. If you see a normal Ionic 4 blank application, that’s mean you ready to go to the next steps.
3. Add Ionic 4 Cordova Native FCM Plugin
To install Ionic 4 Cordova Native Firebase Message Plugin, type this command.
ionic cordova plugin add cordova-plugin-fcm-with-dependecy-updated
npm install @ionic-native/fcm
Next, open and edit src/app/app.module.ts
then add this import.
import { FCM } from '@ionic-native/fcm/ngx';
Add to @NgModule
providers.
providers: [
StatusBar,
SplashScreen,
FCM,
{ provide: RouteReuseStrategy, useClass: IonicRouteStrategy }
],
Next, open and edit src/app/app.component.ts
then add this import.
import { FCM } from '@ionic-native/fcm/ngx';
import { Router } from '@angular/router';
Inject FCM and Router module to the constructor.
constructor(
private platform: Platform,
private splashScreen: SplashScreen,
private statusBar: StatusBar,
private fcm: FCM,
private router: Router
) {
this.initializeApp();
}
Inside platform ready of initializeApp
function, add a function to get FCM token then print out to the browser console.
this.fcm.getToken().then(token => {
console.log(token);
});
Add this function to refresh the FCM token.
this.fcm.onTokenRefresh().subscribe(token => {
console.log(token);
});
Add this function to receive push notification from Firebase Cloud Messaging.
this.fcm.onNotification().subscribe(data => {
console.log(data);
if (data.wasTapped) {
console.log('Received in background');
this.router.navigate([data.landing_page, data.price]);
} else {
console.log('Received in foreground');
this.router.navigate([data.landing_page, data.price]);
}
});
Above example of receiving a push notification from FCM will redirect to the other page with params of data. For that, next, we have to add a new page by type this command.
ionic g page second
Next, modify src/app/app-routing.module.ts
then change the new page route.
const routes: Routes = [
{ path: '', redirectTo: 'home', pathMatch: 'full' },
{ path: 'home', loadChildren: './home/home.module#HomePageModule' },
{ path: 'second/:price', loadChildren: './second/second.module#SecondPageModule' },
];
Next, open and edit src/app/second/second.page.ts
then add this import.
import { ActivatedRoute } from '@angular/router';
Inject that module to the constructor.
constructor(private route: ActivatedRoute) { }
Add a variable for hold data from router parameters.
price: any = '';
Add this line to get data from the router parameters.
constructor(private route: ActivatedRoute) {
this.price = this.route.snapshot.params['price'];
}
Next, open and edit src/app/second/second.page.html
then replace all HTML tags with this.
<ion-header>
<ion-toolbar>
<ion-title>Second</ion-title>
</ion-toolbar>
</ion-header>
<ion-content padding>
<ion-card>
<ion-card-header>
<ion-card-title>Congratulation!</ion-card-title>
</ion-card-header>
<ion-card-content>
You get price from our sponsor:
<h2>{{price}}</h2>
</ion-card-content>
</ion-card>
</ion-content>
If you plan to send push notification to the group of topic, add this lines inside the platform ready.
this.fcm.subscribeToTopic('people');
To unsubscribe from topic, add this line.
this.fcm.unsubscribeFromTopic('marketing');
4. Run and Test Sending and Receiving Push Notification
Before running this Ionic 4 app, we have to copy the downloaded google-services.json
file to the root of the project. Type this command to add the Android platform.
ionic cordova platform add android
Next, copy the google-services.json
to the platform/android/
directory.
cp google-services.json platform/android/
Next, run the Ionic 4 App to the Android device by type this command.
ionic cordova run android
After the app running on the device, check the console from the Google Chrome by type this address chrome://inspect
then choose the inspect link. You should take to the browser inspector, just change to the console tab.
As you can see above, you can take and write down the FCM token for use by Postman. Next, open the Postman application from your computer. Change the method to POST and add this address [https://fcm.googleapis.com/fcm/send](https://fcm.googleapis.com/fcm/send "https://fcm.googleapis.com/fcm/send")
. On the headers, add this key Content-Type
with value application/json
and Authorization
with value key=YOUR_FIREBASE_KEY...
.
Next, add this JSON data to the RAW body.
{
"notification":{
"title":"Ionic 4 Notification",
"body":"This notification sent from POSTMAN using Firebase HTTP protocol",
"sound":"default",
"click_action":"FCM_PLUGIN_ACTIVITY",
"icon":"fcm_push_icon"
},
"data":{
"landing_page":"second",
"price":"$3,000.00"
},
"to":"eadego-nig0:APA91bEtKx9hv50lmQmfzl-bSDdsZyTQ4RkelInfzxrPcZjJaSgDmok3-WQKV5FBu9hrMrkRrcCmf3arkGSviGltg5CyC2F9x1J2m0W7U8PxJ3Zlh7-_tL6VcFdb76hbaLIdZ-dOK15r",
"priority":"high",
"restricted_package_name":""
}
If you want to send by topics recipients, change the value of to
to topics/people
. Next, click the send button and you should see this response.
{
"multicast_id": 7712395953543412819,
"success": 1,
"failure": 0,
"canonical_ids": 0,
"results": [
{
"message_id": "0:1550632139317442%b73443ccb73443cc"
}
]
}
And you will see the notification in your Android device background screen.
If you tap on it, it will open the App and redirect to the second page with this view.
That it’s, the example of receiving push notification using Ionic 4 and Firebase Cloud Messaging. You can grab the full source code from our GitHub.
#ionic #firebase #angular
1611112146
Autocomplete textbox search from database in codeigniter 4 using jQuery Typeahead js. In this tutorial, you will learn how to implement an autocomplete search or textbox search with database using jquery typehead js example.
This tutorial will show you step by step how to implement autocomplete search from database in codeigniter 4 app using typeahead js.
https://www.tutsmake.com/codeigniter-4-autocomplete-textbox-from-database-using-typeahead-js/
#codeigniter 4 ajax autocomplete search #codeigniter 4 ajax autocomplete search from database #autocomplete textbox in jquery example using database in codeigniter #search data from database in codeigniter 4 using ajax #how to search and display data from database in codeigniter 4 using ajax #autocomplete in codeigniter 4 using typeahead js