Skip to content
This repository was archived by the owner on Apr 4, 2023. It is now read-only.

Commit 2cdd46d

Browse files
[ios][messaging] onMessaggeReceived callback not triggered when showNotificationsWhenInForeground is true #1371
1 parent b5a5606 commit 2cdd46d

File tree

4 files changed

+14
-1
lines changed

4 files changed

+14
-1
lines changed

demo-push/app/push-view-model.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export class PushViewModel extends Observable {
4848
messaging.getCurrentPushToken()
4949
.then(token => {
5050
// may be null/undefined if not known yet
51+
console.log(token);
5152
alert({
5253
title: "Current Push Token",
5354
message: (!token ? "Not received yet (note that on iOS this does not work on a simulator)" : token + ("\n\nSee the console log if you want to copy-paste it.")),
@@ -192,7 +193,7 @@ export class PushViewModel extends Observable {
192193
// Whether you want this plugin to always handle the notifications when the app is in foreground.
193194
// Currently used on iOS only. Default false.
194195
// When false, you can still force showing it when the app is in the foreground by adding 'showWhenInForeground' to the notification as mentioned in the readme.
195-
showNotificationsWhenInForeground: false
196+
showNotificationsWhenInForeground: true
196197
})
197198
.then(() => console.log(">>>> Registered for push"))
198199
.catch(err => console.log(">>>> Failed to register for push"));

docs/MESSAGING.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,8 @@ This results in a payload of:
198198
- App in the foreground: `{"foo":"bar", "gcm.message_id":"0:1522952720644653%3194ccac3194ccac", "foreground":true, "title":"My title", "body":"My text"}`
199199
- App in the background: `{"foo":"bar", "gcm.message_id":"0:1522952737879515%3194ccac3194ccac", "title":"My title", "body":"My text", "foreground":false}`
200200

201+
Note that on iOS, when the notification was tapped, the payload will contain `notificationTapped: true`. That may help you with some logic in your app.
202+
201203
### (iOS) background notification example
202204

203205
> Take note of `content_available:true` here

src/firebase.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -548,6 +548,11 @@ export interface Message {
548548
* Any other data you may have added to the notification.
549549
*/
550550
data: any;
551+
/**
552+
* Indicates whether or not the notification was tapped.
553+
* iOS only.
554+
*/
555+
notificationTapped?: boolean;
551556
}
552557

553558
export function init(options?: InitOptions): Promise<any>;

src/messaging/messaging.ios.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,9 +407,14 @@ function _registerForRemoteNotifications(resolve?, reject?) {
407407
userInfoJSON,
408408
inputText
409409
});
410+
410411
if (_notificationActionTakenCallback) {
411412
_processPendingActionTakenNotifications();
412413
}
414+
415+
userInfoJSON.notificationTapped = actionIdentifier === UNNotificationDefaultActionIdentifier;
416+
} else {
417+
userInfoJSON.notificationTapped = false;
413418
}
414419

415420
userInfoJSON.foreground = UIApplication.sharedApplication.applicationState === UIApplicationState.Active;

0 commit comments

Comments
 (0)