Skip to content

Expose inForeground and appDidLaunch #193

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion packages/firebase-messaging-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,11 @@ import { alert } from '@nativescript/core';
import { MessagingCore } from '@nativescript/firebase-messaging-core';

MessagingCore.getInstance().addOnMessage(async (remoteMessage) => {
alert('A new Push message arrived!', JSON.stringify(remoteMessage));
if(MessagingCore.inForeground){
alert('A new Push message arrived with application inForeground!', JSON.stringify(remoteMessage));
}else{
alert('A new Push message arrived with application in background!', JSON.stringify(remoteMessage));
}
});
```

Expand Down
4 changes: 4 additions & 0 deletions packages/firebase-messaging-core/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ export interface IMessagingCore {
export declare class MessagingCore implements IMessagingCore {
static getInstance(): MessagingCore;

static readonly inForeground: boolean;

static readonly appDidLaunch: boolean;

getCurrentToken(): Promise<string>;

hasPermission(): Promise<AuthorizationStatus>;
Expand Down
10 changes: 8 additions & 2 deletions packages/firebase-messaging/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ iOS prevents messages containing notification (or 'alert') payloads from being d
This module provides a requestPermission method which triggers a native permission dialog requesting the user's permission:

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

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

firebase()
.messaging()
.onMessage(async (remoteMessage) => {
alert('A new FCM message arrived!', JSON.stringify(remoteMessage));
if(MessagingCore.inForeground){
alert('A new FCM message arrived with application inForeground!', JSON.stringify(remoteMessage));
}else{
alert('A new FCM message arrived! with application in background!', JSON.stringify(remoteMessage));
}
});
```

Expand Down