|
1 | 1 | /* @flow strict-local */
|
2 |
| -import { DeviceEventEmitter, NativeModules, Platform, PushNotificationIOS } from 'react-native'; |
3 |
| -import type { PushNotificationEventName } from 'react-native/Libraries/PushNotificationIOS/PushNotificationIOS'; |
| 2 | +import { DeviceEventEmitter, NativeModules, Platform } from 'react-native'; |
| 3 | +import PushNotificationIOS from '@react-native-community/push-notification-ios'; |
| 4 | +import type { PushNotificationEventName } from '@react-native-community/push-notification-ios'; |
4 | 5 |
|
5 | 6 | import type { Notification } from './types';
|
6 | 7 | import type { Auth, Dispatch, Identity, Narrow, User } from '../types';
|
@@ -122,8 +123,8 @@ const getInitialNotification = async (): Promise<Notification | null> => {
|
122 | 123 | }
|
123 | 124 |
|
124 | 125 | // This is actually typed as ?Object (and so effectively `any`); but if
|
125 |
| - // present, it must be a JSONable dictionary. (See PushNotificationIOS.js and |
126 |
| - // RCTPushNotificationManager.m in Libraries/PushNotificationIOS.) |
| 126 | + // present, it must be a JSONable dictionary. (See js/index.js and |
| 127 | + // ios/RNCPushNotificationIOS.m in @rnc/push-notification-ios.) |
127 | 128 | const data: ?JSONableDict = notification.getData();
|
128 | 129 | if (!data) {
|
129 | 130 | return null;
|
@@ -177,7 +178,7 @@ export class NotificationListener {
|
177 | 178 | // 'register' -> 'remoteNotificationsRegistered'
|
178 | 179 | // 'registrationError' -> 'remoteNotificationRegistrationError'
|
179 | 180 | PushNotificationIOS.addEventListener(name, handler);
|
180 |
| - this.unsubs.push(() => PushNotificationIOS.removeEventListener(name, handler)); |
| 181 | + this.unsubs.push(() => PushNotificationIOS.removeEventListener(name)); |
181 | 182 | }
|
182 | 183 |
|
183 | 184 | /** Private. */
|
@@ -272,53 +273,46 @@ export class NotificationListener {
|
272 | 273 | export const getNotificationToken = () => {
|
273 | 274 | if (Platform.OS === 'ios') {
|
274 | 275 | // This leads to a call in RNCPushNotificationIOS to this, to
|
275 |
| - // maybe prompt the user to grant permissions: |
276 |
| - // https://developer.apple.com/documentation/uikit/uiapplication/1622932-registerusernotificationsettings?language=objc |
277 |
| - // (deprecated after iOS 10, yikes!). |
| 276 | + // maybe prompt the user to grant authorization, with options for |
| 277 | + // what things to authorize (badge, sound, alert, etc.): |
| 278 | + // https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/1649527-requestauthorizationwithoptions |
278 | 279 | //
|
279 |
| - // (Then, in case we're interested, the library ensures that the |
280 |
| - // Promise we get will resolve with the user's notification |
281 |
| - // settings for the app: whether they've enabled alerts, the badge |
282 |
| - // count, and sound.) |
| 280 | + // If authorization is granted, the library calls this, to have the |
| 281 | + // application register for remote notifications: |
| 282 | + // https://developer.apple.com/documentation/appkit/nsapplication/2967172-registerforremotenotifications?language=occ |
283 | 283 | //
|
284 |
| - // The above-mentioned `registerUserNotificationSettings` function |
285 |
| - // reports the permissions-request result to the app; |
286 |
| - // `AppDelegate`'s `didRegisterUserNotificationSettings` method |
287 |
| - // gets called (it's also deprecated): |
288 |
| - // https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1623022-application?language=objc |
289 |
| - // Following the library's setup instructions, we've asked that |
290 |
| - // method to hand control back to the library. |
| 284 | + // (Then, in case we're interested, the library calls |
| 285 | + // https://developer.apple.com/documentation/usernotifications/unusernotificationcenter/1649524-getnotificationsettingswithcompl |
| 286 | + // and sets the eventual result to be the resolution of the |
| 287 | + // Promise we get, so we can know if the user has enabled |
| 288 | + // alerts, the badge count, and sound.) |
291 | 289 | //
|
292 |
| - // If authorization is granted, the library calls this (not |
293 |
| - // deprecated), to have the application register for remote |
294 |
| - // notifications: |
295 |
| - // https://developer.apple.com/documentation/appkit/nsapplication/2967172-registerforremotenotifications?language=occ |
296 |
| - // That function ends up sending the app a device token; the app |
297 |
| - // receives it in our own code: `AppDelegate`'s |
| 290 | + // The above-mentioned `registerForRemoteNotifications` function |
| 291 | + // ends up sending the app a device token; the app receives it in |
| 292 | + // our own code: `AppDelegate`'s |
298 | 293 | // `didRegisterForRemoteNotificationsWithDeviceToken` method:
|
299 |
| - // https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622958-application?language=objc |
300 |
| - // (not deprecated). Following the library's setup instructions, |
301 |
| - // we've asked that method to hand control back to the library. |
| 294 | + // https://developer.apple.com/documentation/uikit/uiapplicationdelegate/1622958-application?language=objc. |
| 295 | + // Following the library's setup instructions, we've asked that |
| 296 | + // method to hand control back to the library. |
302 | 297 | //
|
303 | 298 | // It looks like the library then creates a notification, with the
|
304 | 299 | // magic-string name "RemoteNotificationsRegistered", using
|
305 |
| - // https://developer.apple.com/documentation/foundation/nsnotificationcenter/1415812-postnotificationname?language=objc |
306 |
| - // (not deprecated). |
| 300 | + // https://developer.apple.com/documentation/foundation/nsnotificationcenter/1415812-postnotificationname?language=objc. |
307 | 301 | // It listens for this notification with
|
308 | 302 | // https://developer.apple.com/documentation/foundation/nsnotificationcenter/1415360-addobserver
|
309 |
| - // (not deprecated) and, upon receipt, sends a React Native event |
310 |
| - // to the JavaScript part of the library. We can listen to this |
311 |
| - // event, with `PushNotificationIOS.addEventListener`, under the |
312 |
| - // alias 'register'. (We can also listen for registration failure |
313 |
| - // under the alias 'registrationError'.) |
| 303 | + // and, upon receipt, sends a React Native event to the JavaScript |
| 304 | + // part of the library. We can listen to this event, with |
| 305 | + // `PushNotificationIOS.addEventListener`, under the alias |
| 306 | + // 'register'. (We can also listen for registration failure under |
| 307 | + // the alias 'registrationError'.) |
314 | 308 | //
|
315 | 309 | // In short, this kicks off a sequence:
|
316 |
| - // permissions / register settings -> |
| 310 | + // authorization, with options -> |
317 | 311 | // register for remote notifications ->
|
318 | 312 | // send event we already have a global listener for
|
319 | 313 | //
|
320 | 314 | // This satisfies the stern warnings in Apple's docs (at the above
|
321 |
| - // links) to request permissions before registering with the push |
| 315 | + // links) to request authorization before registering with the push |
322 | 316 | // notification service.
|
323 | 317 | PushNotificationIOS.requestPermissions();
|
324 | 318 | } else {
|
|
0 commit comments