@teardown/react-native 2.0.29 → 2.0.32
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -19
- package/docs/adapters/device/basic.mdx +7 -7
- package/docs/adapters/device/device-info.mdx +8 -8
- package/docs/adapters/device/expo.mdx +10 -10
- package/docs/adapters/device/index.mdx +51 -20
- package/docs/adapters/notifications/expo.mdx +64 -30
- package/docs/adapters/notifications/firebase.mdx +61 -27
- package/docs/adapters/notifications/index.mdx +120 -39
- package/docs/adapters/notifications/wix.mdx +61 -27
- package/docs/advanced.mdx +99 -3
- package/docs/api-reference.mdx +177 -12
- package/docs/core-concepts.mdx +31 -13
- package/docs/force-updates.mdx +18 -8
- package/docs/hooks-reference.mdx +9 -6
- package/docs/identity.mdx +46 -6
- package/docs/logging.mdx +5 -15
- package/package.json +5 -5
- package/src/clients/api/api.client.ts +4 -0
- package/src/clients/device/device.client.ts +9 -0
- package/src/clients/events/events.client.ts +102 -0
- package/src/clients/events/index.ts +1 -0
- package/src/clients/force-update/force-update.client.ts +27 -10
- package/src/clients/identity/identity.client.test.ts +2 -1
- package/src/clients/identity/identity.client.ts +274 -50
- package/src/clients/logging/logging.client.ts +0 -24
- package/src/exports/index.ts +1 -0
- package/src/hooks/use-force-update.ts +14 -0
- package/src/teardown.core.ts +42 -3
package/README.md
CHANGED
|
@@ -112,7 +112,7 @@ import { useTeardown, useForceUpdate, useSession } from '@teardown/react-native'
|
|
|
112
112
|
function YourComponent() {
|
|
113
113
|
const { core } = useTeardown();
|
|
114
114
|
const session = useSession();
|
|
115
|
-
const {
|
|
115
|
+
const { versionStatus, isUpdateRequired } = useForceUpdate();
|
|
116
116
|
|
|
117
117
|
const handleLogin = async () => {
|
|
118
118
|
await core.identity.identify({
|
|
@@ -129,14 +129,18 @@ function YourComponent() {
|
|
|
129
129
|
|
|
130
130
|
```tsx
|
|
131
131
|
new TeardownCore({
|
|
132
|
-
org_id: string,
|
|
133
|
-
project_id: string,
|
|
134
|
-
api_key: string,
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
132
|
+
org_id: string, // Your organization ID
|
|
133
|
+
project_id: string, // Your project ID
|
|
134
|
+
api_key: string, // Your API key
|
|
135
|
+
environment_slug?: string, // Environment slug (default: "production")
|
|
136
|
+
ingestUrl?: string, // Custom ingest API URL (optional)
|
|
137
|
+
storageAdapter: adapter, // Storage implementation
|
|
138
|
+
deviceAdapter: adapter, // Device info source
|
|
139
|
+
notificationAdapter?: adapter, // Push notification adapter (optional)
|
|
140
|
+
forceUpdate?: {
|
|
141
|
+
checkIntervalMs?: number, // Min time between checks (default: 300000ms/5min)
|
|
142
|
+
checkOnForeground?: boolean, // Check on app foreground (default: true)
|
|
143
|
+
identifyAnonymousDevice?: boolean, // Check even when not identified (default: false)
|
|
140
144
|
},
|
|
141
145
|
});
|
|
142
146
|
```
|
|
@@ -156,16 +160,15 @@ For detailed guides, visit **[teardown.dev/docs](https://teardown.dev/docs)**
|
|
|
156
160
|
|
|
157
161
|
Local documentation is also available in the [docs](./docs) folder:
|
|
158
162
|
|
|
159
|
-
- [Getting Started](./docs/
|
|
160
|
-
- [Core Concepts](./docs/
|
|
161
|
-
- [Identity & Authentication](./docs/
|
|
162
|
-
- [Force Updates](./docs/
|
|
163
|
-
- [
|
|
164
|
-
- [
|
|
165
|
-
- [
|
|
166
|
-
- [
|
|
167
|
-
- [
|
|
168
|
-
- [Advanced Usage](./docs/10-advanced.mdx)
|
|
163
|
+
- [Getting Started](./docs/getting-started.mdx)
|
|
164
|
+
- [Core Concepts](./docs/core-concepts.mdx)
|
|
165
|
+
- [Identity & Authentication](./docs/identity.mdx)
|
|
166
|
+
- [Force Updates](./docs/force-updates.mdx)
|
|
167
|
+
- [Logging](./docs/logging.mdx)
|
|
168
|
+
- [API Reference](./docs/api-reference.mdx)
|
|
169
|
+
- [Hooks Reference](./docs/hooks-reference.mdx)
|
|
170
|
+
- [Advanced Usage](./docs/advanced.mdx)
|
|
171
|
+
- [Adapters](./docs/adapters/index.mdx)
|
|
169
172
|
|
|
170
173
|
## License
|
|
171
174
|
|
|
@@ -33,17 +33,17 @@ The BasicAdapter returns static or minimal information:
|
|
|
33
33
|
|
|
34
34
|
### Application Info
|
|
35
35
|
- `version` - Static value or from app.json
|
|
36
|
-
- `
|
|
37
|
-
- `bundleId` - Static value or from app.json
|
|
36
|
+
- `build_number` - Static value (as number)
|
|
38
37
|
|
|
39
38
|
### Hardware Info
|
|
40
|
-
- `
|
|
41
|
-
- `
|
|
42
|
-
- `
|
|
39
|
+
- `device_name` - "Unknown Device"
|
|
40
|
+
- `device_brand` - "Unknown"
|
|
41
|
+
- `device_type` - "unknown"
|
|
43
42
|
|
|
44
43
|
### OS Info
|
|
45
|
-
- `
|
|
46
|
-
- `
|
|
44
|
+
- `platform` - From React Native `Platform.OS` mapped to `DevicePlatformEnum`
|
|
45
|
+
- `name` - From React Native Platform API
|
|
46
|
+
- `version` - From React Native Platform API
|
|
47
47
|
|
|
48
48
|
## When to Use
|
|
49
49
|
|
|
@@ -44,17 +44,17 @@ import { DeviceInfoAdapter } from '@teardown/react-native/adapters/device-info';
|
|
|
44
44
|
|
|
45
45
|
### Application Info
|
|
46
46
|
- `version` - From `getVersion()`
|
|
47
|
-
- `
|
|
48
|
-
- `bundleId` - From `getBundleId()`
|
|
47
|
+
- `build_number` - From `getBuildNumber()` (as number)
|
|
49
48
|
|
|
50
49
|
### Hardware Info
|
|
51
|
-
- `
|
|
52
|
-
- `
|
|
53
|
-
- `
|
|
50
|
+
- `device_name` - From `getDeviceName()`
|
|
51
|
+
- `device_brand` - From `getBrand()`
|
|
52
|
+
- `device_type` - From `getDeviceType()` (phone, tablet, desktop, tv, unknown)
|
|
54
53
|
|
|
55
54
|
### OS Info
|
|
56
|
-
- `
|
|
57
|
-
- `
|
|
55
|
+
- `platform` - Mapped from React Native `Platform.OS` to `DevicePlatformEnum`
|
|
56
|
+
- `name` - From `getSystemName()`
|
|
57
|
+
- `version` - From `getSystemVersion()`
|
|
58
58
|
|
|
59
59
|
## When to Use
|
|
60
60
|
|
|
@@ -64,7 +64,7 @@ import { DeviceInfoAdapter } from '@teardown/react-native/adapters/device-info';
|
|
|
64
64
|
|
|
65
65
|
## Requirements
|
|
66
66
|
|
|
67
|
-
- `react-native-device-info` >=
|
|
67
|
+
- `react-native-device-info` >= 15.0.0
|
|
68
68
|
- React Native >= 0.60 (autolinking)
|
|
69
69
|
|
|
70
70
|
## Platform Notes
|
|
@@ -37,25 +37,25 @@ import { ExpoDeviceAdapter } from '@teardown/react-native/adapters/expo';
|
|
|
37
37
|
|
|
38
38
|
### Application Info
|
|
39
39
|
- `version` - From `expo-application` `nativeApplicationVersion`
|
|
40
|
-
- `
|
|
41
|
-
- `bundleId` - From `expo-application` `applicationId`
|
|
40
|
+
- `build_number` - From `expo-application` `nativeBuildVersion` (as number)
|
|
42
41
|
|
|
43
42
|
### Hardware Info
|
|
44
|
-
- `
|
|
45
|
-
- `
|
|
46
|
-
- `
|
|
43
|
+
- `device_name` - From `expo-device` `deviceName`
|
|
44
|
+
- `device_brand` - From `expo-device` `brand`
|
|
45
|
+
- `device_type` - From `expo-device` `deviceType` (phone, tablet, desktop, tv, unknown)
|
|
47
46
|
|
|
48
47
|
### OS Info
|
|
49
|
-
- `
|
|
50
|
-
- `
|
|
48
|
+
- `platform` - Mapped from React Native `Platform.OS` to `DevicePlatformEnum`
|
|
49
|
+
- `name` - From `expo-device` `osName`
|
|
50
|
+
- `version` - From `expo-device` `osVersion`
|
|
51
51
|
|
|
52
52
|
## When to Use
|
|
53
53
|
|
|
54
54
|
- Expo managed workflow projects
|
|
55
55
|
- Expo bare workflow projects using Expo modules
|
|
56
|
-
- Projects using Expo SDK
|
|
56
|
+
- Projects using Expo SDK 50+
|
|
57
57
|
|
|
58
58
|
## Requirements
|
|
59
59
|
|
|
60
|
-
- `expo-device` >=
|
|
61
|
-
- `expo-application` >=
|
|
60
|
+
- `expo-device` >= 8.0.0
|
|
61
|
+
- `expo-application` >= 7.0.0
|
|
@@ -22,9 +22,8 @@ All device adapters provide:
|
|
|
22
22
|
|
|
23
23
|
```typescript
|
|
24
24
|
interface ApplicationInfo {
|
|
25
|
-
version: string;
|
|
26
|
-
|
|
27
|
-
bundleId: string; // Bundle identifier (e.g., "com.example.app")
|
|
25
|
+
version: string; // App version (e.g., "1.2.3")
|
|
26
|
+
build_number: number; // Build number (e.g., 45)
|
|
28
27
|
}
|
|
29
28
|
```
|
|
30
29
|
|
|
@@ -32,9 +31,9 @@ interface ApplicationInfo {
|
|
|
32
31
|
|
|
33
32
|
```typescript
|
|
34
33
|
interface HardwareInfo {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
device_name: string; // Device name (e.g., "iPhone 14 Pro")
|
|
35
|
+
device_brand: string; // Manufacturer (e.g., "Apple")
|
|
36
|
+
device_type: string; // Device type (e.g., "phone", "tablet")
|
|
38
37
|
}
|
|
39
38
|
```
|
|
40
39
|
|
|
@@ -42,8 +41,23 @@ interface HardwareInfo {
|
|
|
42
41
|
|
|
43
42
|
```typescript
|
|
44
43
|
interface OSInfo {
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
platform: DevicePlatformEnum; // Platform enum (IOS, ANDROID, etc.)
|
|
45
|
+
name: string; // OS name (e.g., "iOS", "Android")
|
|
46
|
+
version: string; // OS version (e.g., "17.0")
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### DevicePlatformEnum
|
|
51
|
+
|
|
52
|
+
```typescript
|
|
53
|
+
enum DevicePlatformEnum {
|
|
54
|
+
IOS = "IOS",
|
|
55
|
+
ANDROID = "ANDROID",
|
|
56
|
+
WEB = "WEB",
|
|
57
|
+
WINDOWS = "WINDOWS",
|
|
58
|
+
MACOS = "MACOS",
|
|
59
|
+
LINUX = "LINUX",
|
|
60
|
+
UNKNOWN = "UNKNOWN",
|
|
47
61
|
}
|
|
48
62
|
```
|
|
49
63
|
|
|
@@ -52,10 +66,14 @@ interface OSInfo {
|
|
|
52
66
|
```typescript
|
|
53
67
|
import { TeardownCore } from '@teardown/react-native';
|
|
54
68
|
import { ExpoDeviceAdapter } from '@teardown/react-native/adapters/expo';
|
|
69
|
+
import { MMKVStorageAdapter } from '@teardown/react-native/adapters/mmkv';
|
|
55
70
|
|
|
56
71
|
const teardown = new TeardownCore({
|
|
72
|
+
org_id: 'your-org-id',
|
|
73
|
+
project_id: 'your-project-id',
|
|
74
|
+
api_key: 'your-api-key',
|
|
75
|
+
storageAdapter: new MMKVStorageAdapter(),
|
|
57
76
|
deviceAdapter: new ExpoDeviceAdapter(),
|
|
58
|
-
// ... other options
|
|
59
77
|
});
|
|
60
78
|
```
|
|
61
79
|
|
|
@@ -68,34 +86,47 @@ const deviceId = await core.device.getDeviceId();
|
|
|
68
86
|
// Returns a UUID that persists in storage
|
|
69
87
|
```
|
|
70
88
|
|
|
89
|
+
To reset the device ID (device will appear as new install):
|
|
90
|
+
|
|
91
|
+
```typescript
|
|
92
|
+
core.device.reset();
|
|
93
|
+
// Next getDeviceId() call will generate a new ID
|
|
94
|
+
```
|
|
95
|
+
|
|
71
96
|
## Custom Adapter
|
|
72
97
|
|
|
73
|
-
|
|
98
|
+
Extend the `DeviceInfoAdapter` abstract class:
|
|
74
99
|
|
|
75
100
|
```typescript
|
|
76
|
-
import
|
|
77
|
-
|
|
78
|
-
|
|
101
|
+
import {
|
|
102
|
+
DeviceInfoAdapter,
|
|
103
|
+
DevicePlatformEnum,
|
|
104
|
+
type ApplicationInfo,
|
|
105
|
+
type HardwareInfo,
|
|
106
|
+
type OSInfo,
|
|
107
|
+
} from '@teardown/react-native';
|
|
108
|
+
|
|
109
|
+
class CustomDeviceAdapter extends DeviceInfoAdapter {
|
|
79
110
|
get applicationInfo(): ApplicationInfo {
|
|
80
111
|
return {
|
|
81
112
|
version: '1.0.0',
|
|
82
|
-
|
|
83
|
-
bundleId: 'com.example.app',
|
|
113
|
+
build_number: 1,
|
|
84
114
|
};
|
|
85
115
|
}
|
|
86
116
|
|
|
87
117
|
get hardwareInfo(): HardwareInfo {
|
|
88
118
|
return {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
119
|
+
device_name: 'Custom Device',
|
|
120
|
+
device_brand: 'Custom',
|
|
121
|
+
device_type: 'phone',
|
|
92
122
|
};
|
|
93
123
|
}
|
|
94
124
|
|
|
95
125
|
get osInfo(): OSInfo {
|
|
96
126
|
return {
|
|
97
|
-
|
|
98
|
-
|
|
127
|
+
platform: DevicePlatformEnum.IOS,
|
|
128
|
+
name: 'iOS',
|
|
129
|
+
version: '17.0',
|
|
99
130
|
};
|
|
100
131
|
}
|
|
101
132
|
}
|
|
@@ -14,74 +14,104 @@ npx expo install expo-notifications expo-device expo-constants
|
|
|
14
14
|
## Usage
|
|
15
15
|
|
|
16
16
|
```typescript
|
|
17
|
-
import {
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
17
|
+
import { TeardownCore } from '@teardown/react-native';
|
|
18
|
+
import { ExpoNotificationsAdapter } from '@teardown/react-native/expo';
|
|
19
|
+
import { ExpoDeviceAdapter } from '@teardown/react-native/adapters/expo';
|
|
20
|
+
import { MMKVStorageAdapter } from '@teardown/react-native/adapters/mmkv';
|
|
21
|
+
|
|
22
|
+
const teardown = new TeardownCore({
|
|
23
|
+
org_id: 'your-org-id',
|
|
24
|
+
project_id: 'your-project-id',
|
|
25
|
+
api_key: 'your-api-key',
|
|
26
|
+
storageAdapter: new MMKVStorageAdapter(),
|
|
27
|
+
deviceAdapter: new ExpoDeviceAdapter(),
|
|
28
|
+
notificationAdapter: new ExpoNotificationsAdapter(),
|
|
29
|
+
});
|
|
23
30
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
31
|
+
// Access via NotificationsClient
|
|
32
|
+
if (teardown.notifications) {
|
|
33
|
+
const status = await teardown.notifications.requestPermissions();
|
|
34
|
+
if (status.granted) {
|
|
35
|
+
const token = await teardown.notifications.getToken();
|
|
36
|
+
console.log('Expo push token:', token);
|
|
37
|
+
}
|
|
28
38
|
}
|
|
29
39
|
```
|
|
30
40
|
|
|
31
41
|
## Import Path
|
|
32
42
|
|
|
33
43
|
```typescript
|
|
34
|
-
import { ExpoNotificationsAdapter } from '@teardown/react-native/expo
|
|
44
|
+
import { ExpoNotificationsAdapter } from '@teardown/react-native/expo';
|
|
35
45
|
```
|
|
36
46
|
|
|
37
47
|
## API
|
|
38
48
|
|
|
49
|
+
All methods are accessed via `NotificationsClient`, not directly on the adapter.
|
|
50
|
+
|
|
51
|
+
### requestPermissions()
|
|
52
|
+
|
|
53
|
+
Request notification permissions:
|
|
54
|
+
|
|
55
|
+
```typescript
|
|
56
|
+
const status = await teardown.notifications.requestPermissions();
|
|
57
|
+
// Returns: { granted: boolean, canAskAgain: boolean }
|
|
58
|
+
```
|
|
59
|
+
|
|
39
60
|
### getToken()
|
|
40
61
|
|
|
41
62
|
Get the Expo push token:
|
|
42
63
|
|
|
43
64
|
```typescript
|
|
44
|
-
const token = await notifications.getToken();
|
|
65
|
+
const token = await teardown.notifications.getToken();
|
|
45
66
|
// Returns: "ExponentPushToken[xxxxxx]" or null
|
|
46
67
|
```
|
|
47
68
|
|
|
48
|
-
###
|
|
69
|
+
### onNotificationReceived()
|
|
49
70
|
|
|
50
|
-
|
|
71
|
+
Subscribe to foreground notifications:
|
|
51
72
|
|
|
52
73
|
```typescript
|
|
53
|
-
const
|
|
54
|
-
|
|
74
|
+
const unsubscribe = teardown.notifications.onNotificationReceived((notification) => {
|
|
75
|
+
console.log('Received:', notification.title);
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
// Cleanup
|
|
79
|
+
unsubscribe();
|
|
55
80
|
```
|
|
56
81
|
|
|
57
|
-
###
|
|
82
|
+
### onNotificationOpened()
|
|
58
83
|
|
|
59
|
-
|
|
84
|
+
Subscribe to notification taps:
|
|
60
85
|
|
|
61
86
|
```typescript
|
|
62
|
-
const
|
|
87
|
+
const unsubscribe = teardown.notifications.onNotificationOpened((notification) => {
|
|
88
|
+
console.log('User tapped:', notification.title);
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// Cleanup
|
|
92
|
+
unsubscribe();
|
|
63
93
|
```
|
|
64
94
|
|
|
65
|
-
###
|
|
95
|
+
### onTokenRefresh()
|
|
66
96
|
|
|
67
|
-
Subscribe to
|
|
97
|
+
Subscribe to token changes:
|
|
68
98
|
|
|
69
99
|
```typescript
|
|
70
|
-
const unsubscribe = notifications.
|
|
71
|
-
console.log('
|
|
100
|
+
const unsubscribe = teardown.notifications.onTokenChange((token) => {
|
|
101
|
+
console.log('New token:', token);
|
|
72
102
|
});
|
|
73
103
|
|
|
74
104
|
// Cleanup
|
|
75
105
|
unsubscribe();
|
|
76
106
|
```
|
|
77
107
|
|
|
78
|
-
###
|
|
108
|
+
### onDataMessage()
|
|
79
109
|
|
|
80
|
-
Subscribe to
|
|
110
|
+
Subscribe to data-only/silent messages:
|
|
81
111
|
|
|
82
112
|
```typescript
|
|
83
|
-
const unsubscribe = notifications.
|
|
84
|
-
console.log('
|
|
113
|
+
const unsubscribe = teardown.notifications.onDataMessage((message) => {
|
|
114
|
+
console.log('Data message:', message.data);
|
|
85
115
|
});
|
|
86
116
|
|
|
87
117
|
// Cleanup
|
|
@@ -119,9 +149,13 @@ Push notifications require:
|
|
|
119
149
|
- Push notification capability
|
|
120
150
|
- APNs certificate or key
|
|
121
151
|
|
|
152
|
+
## Platform
|
|
153
|
+
|
|
154
|
+
Returns `NotificationPlatformEnum.EXPO`
|
|
155
|
+
|
|
122
156
|
## Requirements
|
|
123
157
|
|
|
124
|
-
- `expo-notifications` >= 0.
|
|
125
|
-
- `expo-device` >=
|
|
126
|
-
- `expo-constants` >=
|
|
158
|
+
- `expo-notifications` >= 0.32
|
|
159
|
+
- `expo-device` >= 8.0.0
|
|
160
|
+
- `expo-constants` >= 17.0.0
|
|
127
161
|
- EAS Build or dev client (not Expo Go)
|
|
@@ -21,74 +21,104 @@ cd ios && pod install
|
|
|
21
21
|
## Usage
|
|
22
22
|
|
|
23
23
|
```typescript
|
|
24
|
-
import {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
24
|
+
import { TeardownCore } from '@teardown/react-native';
|
|
25
|
+
import { FirebaseMessagingAdapter } from '@teardown/react-native/firebase';
|
|
26
|
+
import { DeviceInfoAdapter } from '@teardown/react-native/adapters/device-info';
|
|
27
|
+
import { AsyncStorageAdapter } from '@teardown/react-native/adapters/async-storage';
|
|
28
|
+
|
|
29
|
+
const teardown = new TeardownCore({
|
|
30
|
+
org_id: 'your-org-id',
|
|
31
|
+
project_id: 'your-project-id',
|
|
32
|
+
api_key: 'your-api-key',
|
|
33
|
+
storageAdapter: new AsyncStorageAdapter(),
|
|
34
|
+
deviceAdapter: new DeviceInfoAdapter(),
|
|
35
|
+
notificationAdapter: new FirebaseMessagingAdapter(),
|
|
36
|
+
});
|
|
30
37
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
const
|
|
34
|
-
|
|
38
|
+
// Access via NotificationsClient
|
|
39
|
+
if (teardown.notifications) {
|
|
40
|
+
const status = await teardown.notifications.requestPermissions();
|
|
41
|
+
if (status.granted) {
|
|
42
|
+
const token = await teardown.notifications.getToken();
|
|
43
|
+
console.log('FCM token:', token);
|
|
44
|
+
}
|
|
35
45
|
}
|
|
36
46
|
```
|
|
37
47
|
|
|
38
48
|
## Import Path
|
|
39
49
|
|
|
40
50
|
```typescript
|
|
41
|
-
import { FirebaseMessagingAdapter } from '@teardown/react-native/firebase
|
|
51
|
+
import { FirebaseMessagingAdapter } from '@teardown/react-native/firebase';
|
|
42
52
|
```
|
|
43
53
|
|
|
44
54
|
## API
|
|
45
55
|
|
|
56
|
+
All methods are accessed via `NotificationsClient`, not directly on the adapter.
|
|
57
|
+
|
|
58
|
+
### requestPermissions()
|
|
59
|
+
|
|
60
|
+
Request notification permissions (required on iOS):
|
|
61
|
+
|
|
62
|
+
```typescript
|
|
63
|
+
const status = await teardown.notifications.requestPermissions();
|
|
64
|
+
// Returns: { granted: boolean, canAskAgain: boolean }
|
|
65
|
+
```
|
|
66
|
+
|
|
46
67
|
### getToken()
|
|
47
68
|
|
|
48
69
|
Get the FCM registration token:
|
|
49
70
|
|
|
50
71
|
```typescript
|
|
51
|
-
const token = await notifications.getToken();
|
|
72
|
+
const token = await teardown.notifications.getToken();
|
|
52
73
|
// Returns: FCM token string or null
|
|
53
74
|
```
|
|
54
75
|
|
|
55
|
-
###
|
|
76
|
+
### onNotificationReceived()
|
|
56
77
|
|
|
57
|
-
|
|
78
|
+
Subscribe to foreground notifications:
|
|
58
79
|
|
|
59
80
|
```typescript
|
|
60
|
-
const
|
|
61
|
-
|
|
81
|
+
const unsubscribe = teardown.notifications.onNotificationReceived((notification) => {
|
|
82
|
+
console.log('Received:', notification.title);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
// Cleanup
|
|
86
|
+
unsubscribe();
|
|
62
87
|
```
|
|
63
88
|
|
|
64
|
-
###
|
|
89
|
+
### onNotificationOpened()
|
|
65
90
|
|
|
66
|
-
|
|
91
|
+
Subscribe to notification taps:
|
|
67
92
|
|
|
68
93
|
```typescript
|
|
69
|
-
const
|
|
94
|
+
const unsubscribe = teardown.notifications.onNotificationOpened((notification) => {
|
|
95
|
+
console.log('User tapped:', notification.title);
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Cleanup
|
|
99
|
+
unsubscribe();
|
|
70
100
|
```
|
|
71
101
|
|
|
72
|
-
###
|
|
102
|
+
### onTokenRefresh()
|
|
73
103
|
|
|
74
|
-
Subscribe to
|
|
104
|
+
Subscribe to token changes:
|
|
75
105
|
|
|
76
106
|
```typescript
|
|
77
|
-
const unsubscribe = notifications.
|
|
78
|
-
console.log('
|
|
107
|
+
const unsubscribe = teardown.notifications.onTokenChange((token) => {
|
|
108
|
+
console.log('New FCM token:', token);
|
|
79
109
|
});
|
|
80
110
|
|
|
81
111
|
// Cleanup
|
|
82
112
|
unsubscribe();
|
|
83
113
|
```
|
|
84
114
|
|
|
85
|
-
###
|
|
115
|
+
### onDataMessage()
|
|
86
116
|
|
|
87
|
-
Subscribe to
|
|
117
|
+
Subscribe to data-only messages (silent push):
|
|
88
118
|
|
|
89
119
|
```typescript
|
|
90
|
-
const unsubscribe = notifications.
|
|
91
|
-
console.log('
|
|
120
|
+
const unsubscribe = teardown.notifications.onDataMessage((message) => {
|
|
121
|
+
console.log('Data message:', message.data);
|
|
92
122
|
});
|
|
93
123
|
|
|
94
124
|
// Cleanup
|
|
@@ -135,6 +165,10 @@ messaging().setBackgroundMessageHandler(async (remoteMessage) => {
|
|
|
135
165
|
});
|
|
136
166
|
```
|
|
137
167
|
|
|
168
|
+
## Platform
|
|
169
|
+
|
|
170
|
+
Returns `NotificationPlatformEnum.FCM`
|
|
171
|
+
|
|
138
172
|
## Requirements
|
|
139
173
|
|
|
140
174
|
- `@react-native-firebase/app` >= 18.0.0
|