Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ionic 5 push notifications with Capacitor

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?

like image 302
Sam Barnum Avatar asked Mar 24 '20 01:03

Sam Barnum


People also ask

Does ionic support push notification?

Each platform supports push notifications. They are an easy way to speak directly to your app's users.

How to implement push notifications in ionic-react using Cordova?

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.

Does capacitor support local notifications?

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.

How to implement local notifications in ionic 5?

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 ?

How to send push notifications using capacitor push notification API?

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.


1 Answers

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.

like image 192
jcesarmobile Avatar answered Oct 19 '22 02:10

jcesarmobile