CleverPush Developer Docs

CleverPush Developer Docs

  • SDK Docs
  • API Overview
  • API Reference

›Capacitor SDK

JavaScript SDK

  • Setup
  • Methods

iOS SDK

  • Setup
  • Methods
  • Inbox View
  • Chat
  • Stories
  • Deep Links
  • Live Activities
  • Troubleshooting
  • Changelog

Android SDK

  • Setup
  • Methods
  • Notification Extender Service
  • Inbox View
  • Chat
  • Stories
  • Deep Links
  • Troubleshooting
  • Upgrading
  • Changelog

Capacitor SDK

  • Setup
  • Methods

Cordova SDK

  • Setup
  • Methods
  • Changelog

React Native SDK

  • Setup
  • Methods
  • Changelog

Xamarin SDK

  • Setup
  • Methods
  • Changelog

Flutter SDK

  • Setup
  • Methods
  • Chat
  • Troubleshooting
  • Changelog

Methods

Initialization

Add the initialization code like this:

import { Component } from '@angular/core';
import { Platform } from '@ionic/angular';
import CleverPush from 'cleverpush-capacitor-sdk';

@Component({
  selector: 'app-root',
  templateUrl: 'app.component.html'
})
export class AppComponent {
  constructor(
    private platform: Platform
  ) {
    this.initializeApp();
  }

  initializeApp() {
    this.platform.ready().then(() => {
    // ...
        const notificationReceivedListener = (data) => {
          console.log('CleverPush notification received:', JSON.stringify(data));
        };

        const notificationOpenedListener = (data) => {
          console.log('CleverPush notification opened:', JSON.stringify(data));
        };

        const subscribedListener = (subscriptionId) => {
          console.log('CleverPush subscriptionId:', subscriptionId);
        };

        // set this to `false` to prevent the SDK from automatically subscribing the user on the first launch of the SDK
        const autoRegister = true;

        CleverPush.init(
          "INSERT_YOUR_CHANNEL_ID",
          notificationReceivedListener,
          notificationOpenedListener,
          subscribedListener,
          autoRegister
        );
      }, false);
    });
  }
}

Basic usage

Subscribe:

CleverPush.subscribe();

Unsubscribe:

CleverPush.unsubscribe();

Check if subscribed:

CleverPush.isSubscribed((err, isSubscribed) => {
  
});

Get Subscription ID (after subscribe)

CleverPush.getSubscriptionId((err, subscriptionId) => {
  
});

Notification Received Callback Listener

Instead of a regular NotificationReceivedListener you could also use a NotificationReceivedCallbackListener. This way you can dynamically control if you want to show a notification when the app is running in foreground:

CleverPush.setNotificationReceivedCallbackListener(function(data) {
  console.log('CleverPush notification received:', JSON.stringify(data));
  var showInForeground = true;
  CleverPush.setNotificationReceivedCallbackResult(data.notification._id, showInForeground);
});

(Only supported on Android)

App Banners

This listener will be called when a button in an app banner is clicked.

CleverPush.setAppBannerOpenedListener((action) => {
  console.log('App Banner opened:', action);
});
← SetupNext →
  • Initialization
  • Basic usage
  • Notification Received Callback Listener
  • App Banners
SDKs
JavaScriptiOSAndroidCordovaCapacitorReact NativeXamarinFlutter
Community
TwitterFacebookGitHub
More
API ReferenceAPI OverviewBlogImprintPrivacy PolicyTerms of serviceGDPR
Copyright © 2023 CleverPush