Skip to content

Commit

Permalink
fix(messaging,ios): keep original UNUserNotificationCenter dele… (#3427)
Browse files Browse the repository at this point in the history
* fix(messaging,ios): keep original UNUserNotificationCenter delegate

Keeps a reference to any original UNUserNotificationCenter delegates that are set before we replace the delegate with out own implementation. Internally we will also call the original delegate if our code does not already handle the delegate call. This should keep compatibility with other RN modules that set the delegate.

* v6.4.1-alpha.0

* Revert "v6.4.1-alpha.0"

This reverts commit b355a86

* feat: automatically register with APNs

* docs: typos

* fix: forward delegate call to FIRAuth

Fixes / supersedes #3425

* fix(messaging): add activity check to getInitialNotification (#3495)

* fix(messaging): add activity check to getInitialNotification

* fix(messaging): add activity check to getInitialNotification

* Update .spellcheck.dict.txt

Co-authored-by: Mike Diarmid <[email protected]>

Co-authored-by: Elliot Hesp <[email protected]>
  • Loading branch information
Salakar and Ehesp authored Apr 22, 2020
1 parent 4f61188 commit a800cdb
Show file tree
Hide file tree
Showing 16 changed files with 4,074 additions and 6,319 deletions.
3 changes: 2 additions & 1 deletion .spellcheck.dict.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Analytics
analytics
APIs
APIs.
APNS
APNs
async
auth
Auth
Expand Down Expand Up @@ -123,3 +123,4 @@ v6
VSCode
Wix
Xcode
lifecycle
3 changes: 3 additions & 0 deletions docs/messaging/notifications.md
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ function App() {
}
```

The call to `getInitialNotification` should happen within a React lifecycle method after mounting (e.g. `componentDidMount` or `useEffect`).
If it's called too soon (e.g. within a class constructor or global scope), the notification data may not be available.

# Notifee - Advanced Notifications

FCM provides support for displaying basic notifications to users with minimal integration required. If however you require
Expand Down
52 changes: 30 additions & 22 deletions docs/messaging/usage/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ yarn add @react-native-firebase/messaging
cd ios/ && pod install
```

> iOS requires further configuration steps to be carried out before you can start receiving and sending
> messages through Firebase. Read the documentation on how to [setup iOS with Firebase Messaging](/messaging/usage/ios-setup).
> iOS requires further configuration before you can start receiving and sending
> messages through Firebase. Read the documentation on how to [setup iOS with Firebase Cloud Messaging](/messaging/usage/ios-setup).
If you're using an older version of React Native without auto-linking support, or wish to integrate into an existing project,
you can follow the manual installation steps for [iOS](/messaging/usage/installation/ios) and [Android](/messaging/usage/installation/android).
Expand All @@ -40,31 +40,13 @@ The module also provides basic support for displaying local notifications, to le

# Usage

Before receiving messages from the FCM service, you must first register your device and to use the service on iOS, you need to request the explicit users
permission to accept incoming messages.

## Registering devices with FCM

Before devices can receive and send messages via FCM, they must be registered. The library exposes a `registerDeviceForRemoteMessages`
method which should be called early on in your apps life-cycle. It is recommended that this method is called on every app
boot:

```js
import messaging from '@react-native-firebase/messaging';

async function registerAppWithFCM() {
await messaging().registerDeviceForRemoteMessages();
}
```

## iOS - Requesting permissions

iOS prevents messages from being delivered to devices unless you have received explicit permission from the user. This includes
messages which include data payloads and/or notification payloads.
iOS prevents messages containing notification (or 'alert') payloads from being displayed unless you have received explicit permission from the user.

> To learn more about local notifications, view the [Notifications](/messaging/notifications) documentation.
The module provides a `requestPermission` method which triggers a native permission dialog requesting the user's permission:
This module provides a `requestPermission` method which triggers a native permission dialog requesting the user's permission:

```js
import messaging from '@react-native-firebase/messaging';
Expand Down Expand Up @@ -306,6 +288,32 @@ messaging()

Messaging can be further configured to provide more control over how FCM is handled internally within your application.

## Auto Registration (iOS)

React Native Firebase Messaging automatically registers the device with APNs to receive remote messages. If you need
to manually control registration you can disable this via the `firebase.json` file:

```json
// <projectRoot>/firebase.json
{
"react-native": {
"messaging_ios_auto_register_for_remote_messages": false,
}
}
```

Once auto-registration is disabled you must manually call `registerDeviceForRemoteMessages` in your JavaScript code as
early as possible in your application startup;

```js
import messaging from '@react-native-firebase/messaging';

async function registerAppWithFCM() {
await messaging().registerDeviceForRemoteMessages();
}
```


## Auto initialization

Firebase generates an Instance ID, which FCM uses to generate a registration token and which Analytics uses for data collection.
Expand Down
16 changes: 8 additions & 8 deletions docs/messaging/usage/ios-setup.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ There are also a number of prerequisites which are required to be able to enable

- You must have an active [Apple Developer Account](https://developer.apple.com/membercenter/index.action).
- You must have a physical iOS device to receive messages.
- Firebase Cloud Messaging integrates with the [Apple Push Notification Service (APNS)](https://developer.apple.com/notifications/),
however APNS only works with real devices.
- Firebase Cloud Messaging integrates with the [Apple Push Notification service (APNs)](https://developer.apple.com/notifications/),
however APNs only works with real devices.

# Configuring your app

Expand Down Expand Up @@ -55,10 +55,10 @@ Now ensure that both the "Background fetch" and the "Remote notifications" sub-m

![Enabling the sub-modes](https://images.prismic.io/invertase/3a618574-dd9f-4478-9f39-9834d142b2e5_xcode-background-modes-check.gif?auto=compress,format)

# Linking APNS with FCM
# Linking APNs with FCM

Even though FCM a has limited capability to work without linking with APNS, the below steps are strongly recommended
to ensure the library works as expected. Without linking APNS, your device will not receive messages when in the background
Even though FCM a has limited capability to work without linking with APNs, the below steps are strongly recommended
to ensure the library works as expected. Without linking APNs, your device will not receive messages when in the background
or when quit.

A few steps are required:
Expand All @@ -75,11 +75,11 @@ tab on the account sidebar:

## 1. Registering a key

A key can be generated which gives the FCM full access over the Apple Push Notification (APNS) service. On the "Keys" menu item,
register a new key. The name of the key can be anything, however you must ensure the "Apple Push Notification (APNS)" service
A key can be generated which gives the FCM full access over the Apple Push Notification service (APNs). On the "Keys" menu item,
register a new key. The name of the key can be anything, however you must ensure the APNs service
is enabled:

![Enable "Apple Push Notification (APNS)"](https://images.prismic.io/invertase/01fefe19-132f-4b88-8c17-9dc40357e4ce_apple-key.png?auto=format)
![Enable "Apple Push Notification (APNs)"](https://images.prismic.io/invertase/01fefe19-132f-4b88-8c17-9dc40357e4ce_apple-key.png?auto=format)

Click "Continue" & then "Save". Once saved, you will be presented with a screen displaying the private "Key ID" & the ability
to download the key. Copy the ID, and download the file to your local machine:
Expand Down
4 changes: 2 additions & 2 deletions docs/releases/v6.4.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,8 @@ date: 2020-04-03
- This fixes an issue where FCM would throw a `"The operation couldn’t be completed"` error ([`#2657`](https://github.com/invertase/react-native-firebase/issues/2657))
- `iOS`: direct FCM connection is now fixed.
- When the app was in the foreground, `data-only` messages were not coming through, they are now.
- `iOS`: when running debug build, the APNS token will be registered with FCM as a `"sandbox"` key type
- `iOS`: the original APNS swizzling we implemented was not functioning correctly with `application:didReceiveRemoteNotification:fetchCompletionHandler:`.
- `iOS`: when running debug build, the APNs token will be registered with FCM as a `"sandbox"` key type
- `iOS`: the original APNs swizzling we implemented was not functioning correctly with `application:didReceiveRemoteNotification:fetchCompletionHandler:`.
- We added additional logic whereby this is executed in all scenarios (foreground/background/quit) and replaces a deprecated Apple API.
- This fixes issues with `data-only` messages not being handled by the device
- `iOS`: any custom `FIRMessagingDelegate` methods you add to your `AppDelegate.m` will now also be called internally by React Native Firebase messaging.
Expand Down
Loading

0 comments on commit a800cdb

Please sign in to comment.