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.

addEventListener

addEventListener(type: PushNotificationEvents, callback: EventListenerOrEventListenerObject, options?: boolean | AddEventListenerOptions): void

Listen for events.

removeEventListener

removeEventListener(type: PushNotificationEvents, callback: EventListenerOrEventListenerObject, options?: boolean | EventListenerOptions): void

Remove event listener.

getTopics

getTopics(): Promise<Topic[]>

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

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

tokenRefreshed

tokenRefreshed(token: string)

Called with the token used to send push notifications to the current device.

notificationReceived

notificationReceived(notification: any)

Called with the notification that has been received by the mobile. The content of notification is the content that has been sent from the backend. There will also be a special property called appWasLaunchedFromNotification which indicate wether the app entered the foreground because a notification as pressed on the device or wether the app already was in the foreground when the notification was received.