Skip to content

Commit fa98a76

Browse files
committed
fix(messaging): token change not called & cannot read enum
fixes #16 fixes #17
1 parent 45bfb6b commit fa98a76

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

packages/firebase-messaging/index.android.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { AuthorizationStatus, IMessaging, RemoteMessage } from './common';
44

55
let defaultMessaging: Messaging;
66

7+
export { AuthorizationStatus } from './common';
8+
79
const fb = firebase();
810
Object.defineProperty(fb, 'messaging', {
911
value: () => {
@@ -30,9 +32,13 @@ function ensureCallback() {
3032
public onSuccess(message: string): void {
3133
const callback = this._owner?.get?.()?.[this._propName];
3234
if (typeof callback === 'function') {
33-
try {
34-
callback(JSON.parse(message));
35-
} catch (e) {}
35+
if (this._propName === '_onToken') {
36+
callback(message);
37+
} else {
38+
try {
39+
callback(JSON.parse(message));
40+
} catch (e) { }
41+
}
3642
}
3743
}
3844
}
@@ -159,6 +165,8 @@ export class Messaging implements IMessaging {
159165
this.#onTokenCallback._owner = new WeakRef(this);
160166

161167
org.nativescript.firebase.messaging.FirebaseMessaging.setOnTokenListener(this.#onTokenCallback);
168+
} else {
169+
org.nativescript.firebase.messaging.FirebaseMessaging.setOnTokenListener(null);
162170
}
163171
}
164172
registerDeviceForRemoteMessages(): Promise<void> {

packages/firebase-messaging/index.ios.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ import { Application, ApplicationSettings, Device } from '@nativescript/core';
22
import { deserialize, firebase, FirebaseApp, FirebaseError } from '@nativescript/firebase-core';
33
import { AuthorizationStatus, IMessaging, Permissions, Notification, RemoteMessage } from './common';
44

5+
6+
export { AuthorizationStatus } from './common';
7+
58
declare const FIRApp, TNSFirebaseMessaging;
69

710
let _registerDeviceForRemoteMessages = {

0 commit comments

Comments
 (0)