invertase / invertase/react-native-firebase

[🐛] Messaging module crashes on startup in scene-based life-cycle apps

Open
#8,796 3 comments 0 reactions 0 assignees View on GitHub
Keep Open platform: ios plugin: messaging type: bug
Dominant language
TypeScript
Stars
12.3k
Forks
2.3k
Avg merge
3d 3h
Merged PRs (30d)
79

Description

## Issue

Accessing `[UIApplication sharedApplication].delegate.window` in a scene-based life-cycle app results in a runtime crash, because the `window` property is not populated by default. The `window` property is accessed in `RNFBMessaging+NSNotificationCenter.m` at line 81 and 153. The scene-based life-cycle is available since iOS 13 and will be required soon for all apps. See [this technote](https://developer.apple.com/documentation/technotes/tn3187-migrating-to-the-uikit-scene-based-life-cycle) for further details.

As a quick fix, we can test if the delegate responds to the `window` selector, before comparing it with `!= nil`, to prevent the crash. But this approach prevents getting the React root view, which is used later to store the `isHeadless` property. I am not sure if this breaks the functionality of the messaging module in some way.

---

## Project Files

### Javascript

Click To Expand

#### `package.json`:

```json
# N/A
```

#### `firebase.json` for react-native-firebase v6:

```json
# N/A
```

### iOS

Click To Expand

#### `ios/Podfile`:

- [ ] I'm not using Pods
- [x] I'm using Pods and my Podfile looks like:

```ruby
# N/A
```

#### `AppDelegate.swift`:

```swift
import UIKit
import FirebaseCore

@main
class AppDelegate: UIResponder, UIApplicationDelegate {
func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil
) -> Bool {
FirebaseApp.configure()

return true
}
}
```

---

### Android

Click To Expand

#### Have you converted to AndroidX?

- [ ] my application is an AndroidX application?
- [ ] I am using `android/gradle.settings` `jetifier=true` for Android compatibility?
- [ ] I am using the NPM package `jetifier` for react-native compatibility?

#### `android/build.gradle`:

```groovy
// N/A
```

#### `android/app/build.gradle`:

```groovy
// N/A
```

#### `android/settings.gradle`:

```groovy
// N/A
```

#### `MainApplication.java`:

```java
// N/A
```

#### `AndroidManifest.xml`:

```xml

```

---

## Environment

Click To Expand

**`react-native info` output:**

```
OUTPUT GOES HERE
```

- **Platform that you're experiencing the issue on**:
- [x] iOS
- [ ] Android
- [ ] **iOS** but have not tested behavior on Android
- [ ] **Android** but have not tested behavior on iOS
- [ ] Both
- **`react-native-firebase` version you're using that has this issue:**
- `e.g. 23.5.0`
- **`Firebase` module(s) you're using that has the issue:**
- `e.g. Messaging`
- **Are you using `TypeScript`?**
- `Y` & `5.5.4`

---

- 👉 Check out [`React Native Firebase`](https://twitter.com/rnfirebase) and [`Invertase`](https://twitter.com/invertaseio) on Twitter for updates on the library.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.