My Ionic 5 app wants to send push notifications. The only guide I could find for this is Using Push Notifications with Firebase in an Ionic + Angular App
Why is Firebase necessary? Can I send push notifications without Firebase?
I tried this setup anyway. I didn't get very far.
The guide has this code:
// Request permission to use push notifications
// iOS will prompt user and return if they granted permission or not
// Android will just grant without prompting
PushNotifications.requestPermission().then( result => {
if (result.granted) {
// Register with Apple / Google to receive push via APNS/FCM
PushNotifications.register();
} else {
// Show some error
}
});
However, Typescript is complaining that the correct method is requestPermissions()
not requestPermission()
.
Both fail when running in XCode, probably because I didn't set up pods.
What are my options with Ionic 5 + Capacitor for sending push notifications without Firebase?
Each platform supports push notifications. They are an easy way to speak directly to your app's users.
To build push notification functionality, you can either opt to Install a Cordova plugin for Push (I haven’t tried this yet, but I will), or But since we are using Ionic- React, we need to stick to Capacitor. I know it can get confusing as 4 frameworks are crossing their paths here.
We will see a variety of notification types that can be generated using Local Notifications. We will use a simple Cordova plugin, that works for Capacitor as well, and test the functionality on an Android and iOS app. What is Local Notification ? We have all heard of notifications, and push notifications mostly.
Now you are ready to implement Local notifications in your Ionic 5 app. Local Notification implementation is very easy once you import the plugin correctly. Head to your home.page.ts created with the app. Create a function to schedule your first local notification like this Super easy, right ?
Let’s look at few of the important methods of Capacitor Push Notification API 1. Register function Register function registers your device on FCM server. In response, you receive a token . FCM uses this token to identify your device. That’s how you can pin point a device to send push notifications. You can register simply by 2. Permissions 3.
EDIT:
The guide is now updated to Capacitor 3.
Capacitor 2 guide can be found here
OLD: The guide has been updated to capacitor 2, but capacitor 2 is still in beta.
Install it using next tag
npm install @capacitor/cli@next
npm install @capacitor/core@next
npm install @capacitor/ios@next
npm install @capacitor/android@next
Capacitor uses APNS by default, so if you don’t make the changes in the AppDelegate.swift it should just work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With