Skip to content

Commit 388c3bd

Browse files
authored
Expose inForeground and appDidLaunch (#193)
* add inForeground and appDidLaunch * doc: fix import AuthorizationStatus and add example for inForeground
1 parent 0d14d73 commit 388c3bd

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

packages/firebase-messaging-core/README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ import { alert } from '@nativescript/core';
5252
import { MessagingCore } from '@nativescript/firebase-messaging-core';
5353

5454
MessagingCore.getInstance().addOnMessage(async (remoteMessage) => {
55-
alert('A new Push message arrived!', JSON.stringify(remoteMessage));
55+
if(MessagingCore.inForeground){
56+
alert('A new Push message arrived with application inForeground!', JSON.stringify(remoteMessage));
57+
}else{
58+
alert('A new Push message arrived with application in background!', JSON.stringify(remoteMessage));
59+
}
5660
});
5761
```
5862

packages/firebase-messaging-core/index.d.ts

+4
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export interface IMessagingCore {
4949
export declare class MessagingCore implements IMessagingCore {
5050
static getInstance(): MessagingCore;
5151

52+
static readonly inForeground: boolean;
53+
54+
static readonly appDidLaunch: boolean;
55+
5256
getCurrentToken(): Promise<string>;
5357

5458
hasPermission(): Promise<AuthorizationStatus>;

packages/firebase-messaging/README.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ iOS prevents messages containing notification (or 'alert') payloads from being d
2121
This module provides a requestPermission method which triggers a native permission dialog requesting the user's permission:
2222

2323
```ts
24-
import { firebase, AuthorizationStatus } from '@nativescript/firebase-core';
24+
import { firebase } from '@nativescript/firebase-core';
25+
import { AuthorizationStatus } from "@nativescript/firebase-messaging";
2526
import '@nativescript/firebase-messaging'; // only needs to be imported 1x
2627

2728
async function requestUserPermission() {
@@ -103,11 +104,16 @@ For example, the Alert API could be used to display a new Alert each time a mess
103104
```ts
104105
import { alert } from '@nativescript/core';
105106
import { firebase } from '@nativescript/firebase-core';
107+
import { MessagingCore } from '@nativescript/firebase-messaging-core';
106108

107109
firebase()
108110
.messaging()
109111
.onMessage(async (remoteMessage) => {
110-
alert('A new FCM message arrived!', JSON.stringify(remoteMessage));
112+
if(MessagingCore.inForeground){
113+
alert('A new FCM message arrived with application inForeground!', JSON.stringify(remoteMessage));
114+
}else{
115+
alert('A new FCM message arrived! with application in background!', JSON.stringify(remoteMessage));
116+
}
111117
});
112118
```
113119

0 commit comments

Comments
 (0)