forked from NativeScript/firebase
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ios.ts
80 lines (77 loc) · 1.85 KB
/
index.ios.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
import { firebase, FirebaseApp, FirebaseError } from '@nativescript/firebase-core';
import { IInstallations } from './common';
let defaultInstallations: Installations;
const fb = firebase();
Object.defineProperty(fb, 'installations', {
value: (app?: FirebaseApp) => {
if (!app) {
if (!defaultInstallations) {
defaultInstallations = new Installations();
}
return defaultInstallations;
}
return new Installations(app);
},
writable: false,
});
export class Installations implements IInstallations {
_native: FIRInstallations;
_app: FirebaseApp;
constructor(app?: FirebaseApp) {
if (app?.native) {
this._native = FIRInstallations.installationsWithApp(app.native);
} else {
if (defaultInstallations) {
return defaultInstallations;
}
defaultInstallations = this;
this._native = FIRInstallations.installations();
}
}
delete(): Promise<void> {
return new Promise((resolve, reject) => {
this.native.deleteWithCompletion((error) => {
if (error) {
reject(FirebaseError.fromNative(error));
} else {
resolve();
}
});
});
}
getId(): Promise<string> {
return new Promise((resolve, reject) => {
this.native.installationIDWithCompletion((id, error) => {
if (error) {
reject(FirebaseError.fromNative(error));
} else {
resolve(id);
}
});
});
}
getToken(forceRefresh: boolean = false): Promise<string> {
return new Promise((resolve, reject) => {
this.native.authTokenForcingRefreshCompletion(forceRefresh, (result, error) => {
if (error) {
reject(FirebaseError.fromNative(error));
} else {
resolve(result.authToken);
}
});
});
}
get native() {
return this._native;
}
get ios() {
return this.native;
}
get app(): FirebaseApp {
if (!this._app) {
// @ts-ignore
this._app = FirebaseApp.fromNative(this.native.app);
}
return this._app;
}
}