|
| 1 | +// Type definitions for @react-native-community/push-notification-ios 1.0.2 |
| 2 | +// Project: https://github.com/react-native-community/react-native-push-notification-ios |
| 3 | +// Definitions by: Jules Sam. Randolph <https://github.com/jsamr> |
| 4 | + |
| 5 | +export interface FetchResult { |
| 6 | + NewData: 'UIBackgroundFetchResultNewData' |
| 7 | + NoData: 'UIBackgroundFetchResultNoData' |
| 8 | + ResultFailed: 'UIBackgroundFetchResultFailed' |
| 9 | +} |
| 10 | + |
| 11 | +export interface PushNotification { |
| 12 | + /** |
| 13 | + * An alias for `getAlert` to get the notification's main message string |
| 14 | + */ |
| 15 | + getMessage(): string | Record<string, any> |
| 16 | + |
| 17 | + /** |
| 18 | + * Gets the sound string from the `aps` object |
| 19 | + */ |
| 20 | + getSound(): string |
| 21 | + |
| 22 | + /** |
| 23 | + * Gets the category string from the `aps` object |
| 24 | + */ |
| 25 | + getCategory(): string |
| 26 | + |
| 27 | + /** |
| 28 | + * Gets the notification's main message from the `aps` object |
| 29 | + */ |
| 30 | + getAlert(): string | Record<string, any> |
| 31 | + |
| 32 | + /** |
| 33 | + * Gets the content-available number from the `aps` object |
| 34 | + */ |
| 35 | + getContentAvailable(): number |
| 36 | + |
| 37 | + /** |
| 38 | + * Gets the badge count number from the `aps` object |
| 39 | + */ |
| 40 | + getBadgeCount(): number |
| 41 | + |
| 42 | + /** |
| 43 | + * Gets the data object on the notif |
| 44 | + */ |
| 45 | + getData(): Record<string, any> |
| 46 | + |
| 47 | + /** |
| 48 | + * iOS Only |
| 49 | + * Signifies remote notification handling is complete |
| 50 | + */ |
| 51 | + finish(result: string): void |
| 52 | +} |
| 53 | + |
| 54 | +export interface PresentLocalNotificationDetails { |
| 55 | + alertBody: string |
| 56 | + alertAction: string |
| 57 | + soundName?: string |
| 58 | + category?: string |
| 59 | + userInfo?: Record<string, any> |
| 60 | + applicationIconBadgeNumber?: number |
| 61 | +} |
| 62 | + |
| 63 | +export interface ScheduleLocalNotificationDetails { |
| 64 | + fireDate: Date |
| 65 | + alertBody: string |
| 66 | + alertAction: string |
| 67 | + soundName?: string |
| 68 | + category?: string |
| 69 | + userInfo?: Record<string, any> |
| 70 | + applicationIconBadgeNumber?: number |
| 71 | +} |
| 72 | + |
| 73 | +export interface PushNotificationPermissions { |
| 74 | + alert?: boolean |
| 75 | + badge?: boolean |
| 76 | + sound?: boolean |
| 77 | +} |
| 78 | + |
| 79 | +export type PushNotificationEventName = 'notification' | 'localNotification' | 'register' | 'registrationError' |
| 80 | + |
| 81 | +/** |
| 82 | + * Handle push notifications for your app, including permission handling and icon badge number. |
| 83 | + * @see https://facebook.github.io/react-native/docs/pushnotificationios.html#content |
| 84 | + * |
| 85 | + * //FIXME: BGR: The documentation seems completely off compared to the actual js implementation. I could never get the example to run |
| 86 | + */ |
| 87 | +export interface PushNotificationIOSStatic { |
| 88 | + /** |
| 89 | + * iOS fetch results that best describe the result of a finished remote notification handler. |
| 90 | + * For a list of possible values, see `PushNotificationIOS.FetchResult`. |
| 91 | + */ |
| 92 | + FetchResult: FetchResult |
| 93 | + /** |
| 94 | + * Schedules the localNotification for immediate presentation. |
| 95 | + * details is an object containing: |
| 96 | + * alertBody : The message displayed in the notification alert. |
| 97 | + * alertAction : The "action" displayed beneath an actionable notification. Defaults to "view"; |
| 98 | + * soundName : The sound played when the notification is fired (optional). |
| 99 | + * category : The category of this notification, required for actionable notifications (optional). |
| 100 | + * userInfo : An optional object containing additional notification data. |
| 101 | + * 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. |
| 102 | + */ |
| 103 | + presentLocalNotification(details: PresentLocalNotificationDetails): void |
| 104 | + |
| 105 | + /** |
| 106 | + * Schedules the localNotification for future presentation. |
| 107 | + * details is an object containing: |
| 108 | + * fireDate : The date and time when the system should deliver the notification. |
| 109 | + * alertBody : The message displayed in the notification alert. |
| 110 | + * alertAction : The "action" displayed beneath an actionable notification. Defaults to "view"; |
| 111 | + * soundName : The sound played when the notification is fired (optional). |
| 112 | + * category : The category of this notification, required for actionable notifications (optional). |
| 113 | + * userInfo : An optional object containing additional notification data. |
| 114 | + * applicationIconBadgeNumber (optional) : The number to display as the app's icon badge. Setting the number to 0 removes the icon badge. |
| 115 | + */ |
| 116 | + scheduleLocalNotification(details: ScheduleLocalNotificationDetails): void |
| 117 | + |
| 118 | + /** |
| 119 | + * Cancels all scheduled localNotifications |
| 120 | + */ |
| 121 | + cancelAllLocalNotifications(): void |
| 122 | + |
| 123 | + /** |
| 124 | + * Cancel local notifications. |
| 125 | + * Optionally restricts the set of canceled notifications to those notifications whose userInfo fields match the corresponding fields in the userInfo argument. |
| 126 | + */ |
| 127 | + cancelLocalNotifications(userInfo: Record<string, any>): void |
| 128 | + |
| 129 | + /** |
| 130 | + * Sets the badge number for the app icon on the home screen |
| 131 | + */ |
| 132 | + setApplicationIconBadgeNumber(number: number): void |
| 133 | + |
| 134 | + /** |
| 135 | + * Gets the current badge number for the app icon on the home screen |
| 136 | + */ |
| 137 | + getApplicationIconBadgeNumber(callback: (badge: number) => void): void |
| 138 | + |
| 139 | + /** |
| 140 | + * Gets the local notifications that are currently scheduled. |
| 141 | + */ |
| 142 | + getScheduledLocalNotifications(callback: (notifications: ScheduleLocalNotificationDetails[]) => void): void |
| 143 | + |
| 144 | + /** |
| 145 | + * Attaches a listener to remote notifications while the app is running in the |
| 146 | + * foreground or the background. |
| 147 | + * |
| 148 | + * The handler will get be invoked with an instance of `PushNotificationIOS` |
| 149 | + * |
| 150 | + * The type MUST be 'notification' |
| 151 | + */ |
| 152 | + addEventListener( |
| 153 | + type: 'notification' | 'localNotification', |
| 154 | + handler: (notification: PushNotification) => void, |
| 155 | + ): void |
| 156 | + |
| 157 | + /** |
| 158 | + * Fired when the user registers for remote notifications. |
| 159 | + * |
| 160 | + * The handler will be invoked with a hex string representing the deviceToken. |
| 161 | + * |
| 162 | + * The type MUST be 'register' |
| 163 | + */ |
| 164 | + addEventListener(type: 'register', handler: (deviceToken: string) => void): void |
| 165 | + |
| 166 | + /** |
| 167 | + * Fired when the user fails to register for remote notifications. |
| 168 | + * Typically occurs when APNS is having issues, or the device is a simulator. |
| 169 | + * |
| 170 | + * The handler will be invoked with {message: string, code: number, details: any}. |
| 171 | + * |
| 172 | + * The type MUST be 'registrationError' |
| 173 | + */ |
| 174 | + addEventListener( |
| 175 | + type: 'registrationError', |
| 176 | + handler: (error: { message: string; code: number; details: any }) => void, |
| 177 | + ): void |
| 178 | + |
| 179 | + /** |
| 180 | + * Removes the event listener. Do this in `componentWillUnmount` to prevent |
| 181 | + * memory leaks |
| 182 | + */ |
| 183 | + removeEventListener( |
| 184 | + type: PushNotificationEventName, |
| 185 | + handler: |
| 186 | + | ((notification: PushNotification) => void) |
| 187 | + | ((deviceToken: string) => void) |
| 188 | + | ((error: { message: string; code: number; details: any }) => void), |
| 189 | + ): void |
| 190 | + |
| 191 | + /** |
| 192 | + * Requests all notification permissions from iOS, prompting the user's |
| 193 | + * dialog box. |
| 194 | + */ |
| 195 | + requestPermissions( |
| 196 | + permissions?: PushNotificationPermissions[] | PushNotificationPermissions, |
| 197 | + ): Promise<PushNotificationPermissions> |
| 198 | + |
| 199 | + /** |
| 200 | + * Unregister for all remote notifications received via Apple Push |
| 201 | + * Notification service. |
| 202 | + * You should call this method in rare circumstances only, such as when |
| 203 | + * a new version of the app removes support for all types of remote |
| 204 | + * notifications. Users can temporarily prevent apps from receiving |
| 205 | + * remote notifications through the Notifications section of the |
| 206 | + * Settings app. Apps unregistered through this method can always |
| 207 | + * re-register. |
| 208 | + */ |
| 209 | + abandonPermissions(): void |
| 210 | + |
| 211 | + /** |
| 212 | + * See what push permissions are currently enabled. `callback` will be |
| 213 | + * invoked with a `permissions` object: |
| 214 | + * |
| 215 | + * - `alert` :boolean |
| 216 | + * - `badge` :boolean |
| 217 | + * - `sound` :boolean |
| 218 | + */ |
| 219 | + checkPermissions(callback: (permissions: PushNotificationPermissions) => void): void |
| 220 | + |
| 221 | + /** |
| 222 | + * This method returns a promise that resolves to either the notification |
| 223 | + * object if the app was launched by a push notification, or `null` otherwise. |
| 224 | + */ |
| 225 | + getInitialNotification(): Promise<PushNotification> |
| 226 | +} |
| 227 | + |
| 228 | +declare const PushNotificationIOS: PushNotificationIOSStatic |
| 229 | + |
| 230 | +export = PushNotificationIOS |
| 231 | + |
0 commit comments