1/** 2 * Copyright (c) Meta Platforms, Inc. and affiliates. 3 * 4 * This source code is licensed under the MIT license found in the 5 * LICENSE file in the root directory of this source tree. 6 * 7 * @format 8 */ 9 10export interface PushNotificationPermissions { 11 alert?: boolean | undefined; 12 badge?: boolean | undefined; 13 sound?: boolean | undefined; 14} 15 16export interface PushNotification { 17 /** 18 * An alias for `getAlert` to get the notification's main message string 19 */ 20 getMessage(): string | Object; 21 22 /** 23 * Gets the sound string from the `aps` object 24 */ 25 getSound(): string; 26 27 /** 28 * Gets the category string from the `aps` object 29 */ 30 getCategory(): string; 31 32 /** 33 * Gets the notification's main message from the `aps` object 34 */ 35 getAlert(): string | Object; 36 37 /** 38 * Gets the content-available number from the `aps` object 39 */ 40 getContentAvailable(): number; 41 42 /** 43 * Gets the badge count number from the `aps` object 44 */ 45 getBadgeCount(): number; 46 47 /** 48 * Gets the data object on the notif 49 */ 50 getData(): Object; 51 52 /** 53 * Gets the thread ID on the notif 54 */ 55 getThreadId(): string; 56 57 /** 58 * iOS Only 59 * Signifies remote notification handling is complete 60 */ 61 finish(result: string): void; 62} 63 64type PresentLocalNotificationDetails = { 65 alertBody: string; 66 alertAction: string; 67 alertTitle?: string | undefined; 68 soundName?: string | undefined; 69 category?: string | undefined; 70 userInfo?: Object | undefined; 71 applicationIconBadgeNumber?: number | undefined; 72}; 73 74type ScheduleLocalNotificationDetails = { 75 alertAction?: string | undefined; 76 alertBody?: string | undefined; 77 alertTitle?: string | undefined; 78 applicationIconBadgeNumber?: number | undefined; 79 category?: string | undefined; 80 fireDate?: number | string | undefined; 81 isSilent?: boolean | undefined; 82 repeatInterval?: 83 | 'year' 84 | 'month' 85 | 'week' 86 | 'day' 87 | 'hour' 88 | 'minute' 89 | undefined; 90 soundName?: string | undefined; 91 userInfo?: Object | undefined; 92}; 93 94export type PushNotificationEventName = 95 | 'notification' 96 | 'localNotification' 97 | 'register' 98 | 'registrationError'; 99 100type FetchResult = { 101 NewData: 'UIBackgroundFetchResultNewData'; 102 NoData: 'UIBackgroundFetchResultNoData'; 103 ResultFailed: 'UIBackgroundFetchResultFailed'; 104}; 105 106/** 107 * Handle push notifications for your app, including permission handling and icon badge number. 108 * @see https://reactnative.dev/docs/pushnotificationios#content 109 * 110 * //FIXME: BGR: The documentation seems completely off compared to the actual js implementation. I could never get the example to run 111 */ 112export interface PushNotificationIOSStatic { 113 /** 114 * Schedules the localNotification for immediate presentation. 115 * details is an object containing: 116 * alertBody : The message displayed in the notification alert. 117 * alertAction : The "action" displayed beneath an actionable notification. Defaults to "view"; 118 * soundName : The sound played when the notification is fired (optional). 119 * category : The category of this notification, required for actionable notifications (optional). 120 * userInfo : An optional object containing additional notification data. 121 * applicationIconBadgeNumber (optional) : The number to display as the app's icon badge. The default value of this property is 0, which means that no badge is displayed. 122 */ 123 presentLocalNotification(details: PresentLocalNotificationDetails): void; 124 125 /** 126 * Schedules the localNotification for future presentation. 127 * details is an object containing: 128 * fireDate : The date and time when the system should deliver the notification. 129 * alertBody : The message displayed in the notification alert. 130 * alertAction : The "action" displayed beneath an actionable notification. Defaults to "view"; 131 * soundName : The sound played when the notification is fired (optional). 132 * category : The category of this notification, required for actionable notifications (optional). 133 * userInfo : An optional object containing additional notification data. 134 * applicationIconBadgeNumber (optional) : The number to display as the app's icon badge. Setting the number to 0 removes the icon badge. 135 */ 136 scheduleLocalNotification(details: ScheduleLocalNotificationDetails): void; 137 138 /** 139 * Cancels all scheduled localNotifications 140 */ 141 cancelAllLocalNotifications(): void; 142 143 /** 144 * Remove all delivered notifications from Notification Center. 145 */ 146 removeAllDeliveredNotifications(): void; 147 148 /** 149 * Provides you with a list of the app’s notifications that are still displayed in Notification Center. 150 */ 151 getDeliveredNotifications(callback: (notifications: Object[]) => void): void; 152 153 /** 154 * Removes the specified notifications from Notification Center 155 */ 156 removeDeliveredNotifications(identifiers: string[]): void; 157 158 /** 159 * Cancel local notifications. 160 * Optionally restricts the set of canceled notifications to those notifications whose userInfo fields match the corresponding fields in the userInfo argument. 161 */ 162 cancelLocalNotifications(userInfo: Object): void; 163 164 /** 165 * Sets the badge number for the app icon on the home screen 166 */ 167 setApplicationIconBadgeNumber(number: number): void; 168 169 /** 170 * Gets the current badge number for the app icon on the home screen 171 */ 172 getApplicationIconBadgeNumber(callback: (badge: number) => void): void; 173 174 /** 175 * Gets the local notifications that are currently scheduled. 176 */ 177 getScheduledLocalNotifications( 178 callback: (notifications: ScheduleLocalNotificationDetails[]) => void, 179 ): void; 180 181 /** 182 * Attaches a listener to remote notifications while the app is running in the 183 * foreground or the background. 184 * 185 * The handler will get be invoked with an instance of `PushNotificationIOS` 186 * 187 * The type MUST be 'notification' 188 */ 189 addEventListener( 190 type: 'notification' | 'localNotification', 191 handler: (notification: PushNotification) => void, 192 ): void; 193 194 /** 195 * Fired when the user registers for remote notifications. 196 * 197 * The handler will be invoked with a hex string representing the deviceToken. 198 * 199 * The type MUST be 'register' 200 */ 201 addEventListener( 202 type: 'register', 203 handler: (deviceToken: string) => void, 204 ): void; 205 206 /** 207 * Fired when the user fails to register for remote notifications. 208 * Typically occurs when APNS is having issues, or the device is a simulator. 209 * 210 * The handler will be invoked with {message: string, code: number, details: any}. 211 * 212 * The type MUST be 'registrationError' 213 */ 214 addEventListener( 215 type: 'registrationError', 216 handler: (error: {message: string; code: number; details: any}) => void, 217 ): void; 218 219 /** 220 * Removes the event listener. Do this in `componentWillUnmount` to prevent 221 * memory leaks 222 */ 223 removeEventListener( 224 type: PushNotificationEventName, 225 handler: 226 | ((notification: PushNotification) => void) 227 | ((deviceToken: string) => void) 228 | ((error: {message: string; code: number; details: any}) => void), 229 ): void; 230 231 /** 232 * Requests all notification permissions from iOS, prompting the user's 233 * dialog box. 234 */ 235 requestPermissions(permissions?: PushNotificationPermissions[]): void; 236 237 /** 238 * Requests all notification permissions from iOS, prompting the user's 239 * dialog box. 240 */ 241 requestPermissions( 242 permissions?: PushNotificationPermissions, 243 ): Promise<PushNotificationPermissions>; 244 245 /** 246 * Unregister for all remote notifications received via Apple Push 247 * Notification service. 248 * You should call this method in rare circumstances only, such as when 249 * a new version of the app removes support for all types of remote 250 * notifications. Users can temporarily prevent apps from receiving 251 * remote notifications through the Notifications section of the 252 * Settings app. Apps unregistered through this method can always 253 * re-register. 254 */ 255 abandonPermissions(): void; 256 257 /** 258 * See what push permissions are currently enabled. `callback` will be 259 * invoked with a `permissions` object: 260 * 261 * - `alert` :boolean 262 * - `badge` :boolean 263 * - `sound` :boolean 264 */ 265 checkPermissions( 266 callback: (permissions: PushNotificationPermissions) => void, 267 ): void; 268 269 /** 270 * This method returns a promise that resolves to either the notification 271 * object if the app was launched by a push notification, or `null` otherwise. 272 */ 273 getInitialNotification(): Promise<PushNotification | null>; 274 275 /** 276 * iOS fetch results that best describe the result of a finished remote notification handler. 277 * For a list of possible values, see `PushNotificationIOS.FetchResult`. 278 */ 279 FetchResult: FetchResult; 280} 281 282/** 283 * PushNotificationIOS has been extracted from react-native core and will be removed in a future release. 284 * It can now be installed and imported from `@react-native-community/push-notification-ios` instead of 'react-native'. 285 * @see https://github.com/react-native-community/react-native-push-notification-ios 286 * @deprecated 287 */ 288export const PushNotificationIOS: PushNotificationIOSStatic; 289/** 290 * PushNotificationIOS has been extracted from react-native core and will be removed in a future release. 291 * It can now be installed and imported from `@react-native-community/push-notification-ios` instead of 'react-native'. 292 * @see https://github.com/react-native-community/react-native-push-notification-ios 293 * @deprecated 294 */ 295export type PushNotificationIOS = PushNotificationIOSStatic; 296