| 25 | }); |
| 26 | |
| 27 | export class Messaging implements IMessaging { |
| 28 | _app: FirebaseApp; |
| 29 | _onMessage?: (message: RemoteMessage) => void; |
| 30 | _onToken?: (token: string) => void; |
| 31 | _onNotificationTap?: (message: RemoteMessage) => void; |
| 32 | _instance: MessagingCore; |
| 33 | constructor() { |
| 34 | if (defaultMessaging) { |
| 35 | return defaultMessaging; |
| 36 | } |
| 37 | defaultMessaging = this; |
| 38 | this._instance = MessagingCore.getInstance(); |
| 39 | } |
| 40 | |
| 41 | get showNotificationsWhenInForeground(): boolean { |
| 42 | return NSCFirebaseMessagingCore.showNotificationsWhenInForeground; |
| 43 | } |
| 44 | |
| 45 | set showNotificationsWhenInForeground(value: boolean) { |
| 46 | NSCFirebaseMessagingCore.showNotificationsWhenInForeground = value; |
| 47 | } |
| 48 | |
| 49 | getToken(): Promise<string> { |
| 50 | return new Promise((resolve, reject) => { |
| 51 | if (!TNSFirebaseCore.isSimulator() && !UIApplication.sharedApplication.registeredForRemoteNotifications) { |
| 52 | reject(new Error('You must be registered for remote messages before calling getToken, see messaging().registerDeviceForRemoteMessages()')); |
| 53 | return; |
| 54 | } |
| 55 | this.native?.tokenWithCompletion((token, error) => { |
| 56 | if (error) { |
| 57 | reject(FirebaseError.fromNative(error)); |
| 58 | } else { |
| 59 | resolve(token); |
| 60 | } |
| 61 | }); |
| 62 | }); |
| 63 | } |
| 64 | |
| 65 | getAPNSToken() { |
| 66 | const token = this.native.APNSToken; |
| 67 | if (!token) { |
| 68 | return null; |
| 69 | } |
| 70 | return NSCFirebaseMessagingCore.APNSTokenToString(token); |
| 71 | } |
| 72 | |
| 73 | hasPermission(): Promise<AuthorizationStatus> { |
| 74 | return this._instance.hasPermission() as any; |
| 75 | } |
| 76 | |
| 77 | onMessage(listener: (message: RemoteMessage) => any) { |
| 78 | if (!listener && this._onMessage) { |
| 79 | this._instance.removeOnMessage(this._onMessage); |
| 80 | } else { |
| 81 | this._instance.addOnMessage(listener); |
| 82 | } |
| 83 | |
| 84 | this._onMessage = listener; |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…