Skip to content

Commit 48be8fc

Browse files
committed
feat: use channelId directly in openSettings
1 parent 235218d commit 48be8fc

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

example/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export default function App() {
1212
if (status !== 'granted') {
1313
await requestNotifications(['alert', 'sound']);
1414
}
15-
NotificationsUtils.openSettings({ channelId: 'default' });
15+
NotificationsUtils.openSettings('default');
1616
};
1717

1818
return (

src/index.ts

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,39 @@
11
import { Platform } from 'react-native';
22
import NotificationsUtilsModule from './NotificationsUtilsModule';
33

4-
type OpenSettingsOptions = {
5-
channelId?: string;
6-
};
7-
84
interface INotificationsUtils {
95
/**
106
* API used to open the Platform specific System settings for the application.
117
*
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
2120
*
22-
* On iOS, this is a no-op & instantly resolves.
2321
*
2422
* @platform android
2523
* @param channelId The ID of the channel which will be opened. Can be ignored/omitted to display the
2624
* overall notification settings.
2725
*/
28-
openSettings(options?: OpenSettingsOptions): Promise<void>;
26+
openSettings(channelId?: string): void;
2927
}
3028

3129
const NotificationsUtils: INotificationsUtils = {
32-
openSettings: (options) => {
30+
openSettings: (channelId) => {
3331
if (Platform.OS === 'android') {
34-
if (typeof options?.channelId !== 'string') {
32+
if (channelId && typeof channelId !== 'string') {
3533
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}.`
3735
);
3836
}
39-
const { channelId } = options;
4037

4138
return NotificationsUtilsModule.openAppNotificationsSettings(channelId);
4239
}

0 commit comments

Comments
 (0)