MCPcopy Index your code
hub / github.com/NativeScript/firebase / Messaging

Class Messaging

packages/firebase-messaging/index.ios.ts:27–174  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

25});
26
27export 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;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…