I am encountering an error when trying to register the foreground service using ReactNativeForegroundService
from the @supersami/rn-foreground-service
library. The same code works correctly on Android, but I am facing issues on iOS.
Code:
import ReactNativeForegroundService from "@supersami/rn-foreground-service";
const config = {
config: {
alert: true,
onServiceErrorCallBack: function () {
console.warn('[ReactNativeForegroundService] onServiceErrorCallBack', arguments);
},
}
};
ReactNativeForegroundService.register(config);
Error:
ERROR Invariant Violation: `new NativeEventEmitter()` requires a non-null argument., js engine: hermes
WARN Module ReactNativeEventEmitter requires main queue setup since it overrides `init` but doesn't implement `requiresMainQueueSetup`. In a future release React Native will default to initializing all native modules on a background thread unless explicitly opted-out of.
LOG Running "Cerge" with {"rootTag":21,"initialProps":{}}
Environment:
-
React Native version: “0.71.19”
-
Library version: “^2.1.1”
-
JS Engine: Hermes
-
Platform: iOS
Steps to Reproduce:
-
Install the
@supersami/rn-foreground-service
library. -
Use the
ReactNativeForegroundService.register(config)
method in the code as shown above. -
Run the app on iOS with Hermes enabled.
Expected Behavior: The service should register without errors.
Actual Behavior: The error new NativeEventEmitter() requires a non-null argument
occurs, and the warning about requiresMainQueueSetup
appears.
Additional Context: This issue appears to be related to how the NativeEventEmitter
is being initialized with a null or undefined argument. The warning suggests the module may need to implement requiresMainQueueSetup
.
I tried installing the latest version of the @supersami/rn-foreground-service
library and registering the service using both the configuration method and the simplified approach like this:
ReactNativeForegroundService.register({id: 144});
However, nothing worked, and I still received the same error.