|
1 | 1 | import { Platform } from 'react-native';
|
2 | 2 | import NotificationsUtilsModule from './NotificationsUtilsModule';
|
3 | 3 |
|
4 |
| -type OpenSettingsOptions = { |
5 |
| - channelId?: string; |
6 |
| -}; |
7 |
| - |
8 | 4 | interface INotificationsUtils {
|
9 | 5 | /**
|
10 | 6 | * API used to open the Platform specific System settings for the application.
|
11 | 7 | *
|
12 |
| - * If the API version is >= 26: |
13 |
| - * - With no `channelId`, the notification settings screen is displayed. |
14 |
| - * - With a `channelId`, the notification settings screen for the specific channel is displayed. |
15 |
| - * |
16 |
| - * If the API version is < 26, the application settings screen is displayed. The `channelId` |
17 |
| - * is ignored. |
18 |
| - * |
19 |
| - * If an invalid `channelId` is provided (e.g. does not exist), the settings screen will redirect |
20 |
| - * back to your application. |
| 8 | + * On Android: |
| 9 | + * API version is >= 26 with `channelId` will open the channel settings. if `channelI` is not provided, the app's notification settings will be opened. |
| 10 | + * API version is < 26, the application settings screen is opened. |
| 11 | + * On iOS: |
| 12 | + * If the version of iOS is >= 15.4, the app's notification settings screen is displayed. |
| 13 | + * If the version of iOS is < 15.4, the app's settings screen is displayed. |
| 14 | + * On iOS: |
| 15 | + * If the version of iOS is >= 15.4, the app's notification settings screen is displayed. |
| 16 | + * If the version of iOS is < 15.4, the app's settings screen is displayed. |
| 17 | + * @see https://developer.apple.com/documentation/uikit/uiapplication/4013180-opennotificationsettingsurlstrin |
| 18 | + * @see https://developer.apple.com/documentation/uikit/uiapplicationopennotificationsettingsurlstring?language=objc |
| 19 | + * @see https://developer.apple.com/documentation/uikit/uiapplication/1623042-opensettingsurlstring |
21 | 20 | *
|
22 |
| - * On iOS, this is a no-op & instantly resolves. |
23 | 21 | *
|
24 | 22 | * @platform android
|
25 | 23 | * @param channelId The ID of the channel which will be opened. Can be ignored/omitted to display the
|
26 | 24 | * overall notification settings.
|
27 | 25 | */
|
28 |
| - openSettings(options?: OpenSettingsOptions): Promise<void>; |
| 26 | + openSettings(channelId?: string): void; |
29 | 27 | }
|
30 | 28 |
|
31 | 29 | const NotificationsUtils: INotificationsUtils = {
|
32 |
| - openSettings: (options) => { |
| 30 | + openSettings: (channelId) => { |
33 | 31 | if (Platform.OS === 'android') {
|
34 |
| - if (typeof options?.channelId !== 'string') { |
| 32 | + if (channelId && typeof channelId !== 'string') { |
35 | 33 | throw new Error(
|
36 |
| - `NotificationsUtils.openSettings: Expected 'channelId' to be a string, got ${typeof options?.channelId}.` |
| 34 | + `NotificationsUtils.openSettings: Expected 'channelId' to be a string, got ${typeof channelId}.` |
37 | 35 | );
|
38 | 36 | }
|
39 |
| - const { channelId } = options; |
40 | 37 |
|
41 | 38 | return NotificationsUtilsModule.openAppNotificationsSettings(channelId);
|
42 | 39 | }
|
|
0 commit comments