Push notifications

The purpose of the push notification integration is to make it possible to send push notifications to the users of the app.

Introduction

The push notification integration makes it possible for you to send push notifications to the users of the app using the Firebase Cloud Messaging service.

Integration name: startiapp.PushNotification

Getting started

The app uses Firebase Cloud Messaging (FCM) for the push notification integration.

We suggest you start out by reading about integrating your server to FCM.

Afterwards you should be able to read the most important part, which is about sending push notifications. Here you can read about how you send to individual devices and how you send to topics and the page contains examples from the various supported SDK’s and REST examples too.

The Firebase Admin SDK has support for backends written in C#, Node, Java, Python and Go. If you use something else there’s support for simple HTTP calls too using the FCM HTTP v1 API.

Methods

requestAccess

requestAccess(): Promise<boolean>

This method requests the user for permissions to use push notifications. When calling this method the result is a bit different on the two platforms. On iOS the user will be asked if it’s okay to receive push notifications. On Android nothing happens in the user interface. The method returns true if the user accepted the request to receive push notifications and false if he declined the request.

Note: The user will only see the popup the first time he is asked on iOS. If the method is called again the user won’t see anything.

getToken

getToken(): Promise<string>

This method returns the token which should be used to send push notifications.

setBadgeCount

setBadgeCount(count: number): void

This method sets the badge count on the app icon.

Setting the badge count to 0 will remove the badge from the app icon.

subscribeToTopics

subscribeToTopics(topics: string[]): Promise<void>;

Subscribe to firebase topics.

unsubscribeFromTopics

unsubscribeFromTopics(topics: string[]): Promise<void>;

Unsubscribe from firebase topics.

getTopics

getTopics(): Promise<Topic[]>

This method returns a list of all the topics from the manager platform.

renderTopics

renderTopics(): Promise<void>;

This method renders topics mustache template.

Topic

class Topic {
  topic: string; // the id of the topic (e.g. "hello-world")
  name: string; // the name of the topic which can be shown to the user (e.g. "Hello world")
  subscribed: boolean; // true if the device is subscribed to the topic

  subscribe(): void; // subscribe to the topic
  unsubscribe(): void; // unsubscribe from the topic
}

Events

How to listen for events.

tokenRefreshed

startiapp.PushNotification.addEventListener(
    'tokenRefreshed',
    function (event) {
        console.log(event.detail);
    }
);

This event is fired when the token used to send push notifications to the current device has been refreshed. The event detail will be the token string.

notificationReceived

startiapp.PushNotification.addEventListener(
    'notificationReceived',
    function (event) {
        console.log(event.detail);
    }
);

This event is fired when a push notification has been received by the device. The event detail will contain the following data:

{
  title: string; // the title of the notification
  body: string; // the body of the notification
  tappedByUser: boolean; // true if the user tapped the notification
  isSilentInForeground: boolean; // true if the notification was received in the foreground and was hidden from the user
}