Rapsssito / react-native-background-actions

React Native background service library for running background tasks forever in Android & iOS.
MIT License
796 stars 115 forks source link

Invariant Violation: `new NativeEventEmitter()` requires a non-null argument., js engine: hermes Getting this issue in iOS #204

Closed Malhar99 closed 6 months ago

Malhar99 commented 9 months ago

import BackgroundService from 'react-native-background-actions';

const sleep = time => new Promise(resolve => setTimeout(() => resolve(), time));

// You can do anything in your task such as network requests, timers and so on, // as long as it doesn't touch UI. Once your task completes (i.e. the promise is resolved), // React Native will go into "paused" mode (unless there are other tasks running, // or there is a foreground app). const veryIntensiveTask = async taskDataArguments => { // Example of an infinite loop task const {delay} = taskDataArguments; await new Promise(async resolve => { for (let i = 0; BackgroundService.isRunning(); i++) { console.log(i); await sleep(delay); } }); };

const backgroundTask = async () => { const options = { taskName: 'Example', taskTitle: 'ExampleTask title', taskDesc: 'ExampleTask description', taskIcon: { name: 'ic_launcher', type: 'mipmap', }, color: '#ff00ff', linkingURI: 'yourSchemeHere://chat/jane', // See Deep Linking for more info parameters: { delay: 1000, }, };

await BackgroundService.start(veryIntensiveTask, {});

BackgroundService.on('expiration', () => {
  console.log('I am being closed :(');
});

};

backgroundTask();

"react-native-background-actions": "^3.0.1", "react-native": "0.72.4",

Need urgent solution

Jaseyacey commented 6 months ago

Did you get a solution?

Jaseyacey commented 6 months ago

I found a solution by deleting pods and podfile.lock and then running pod install Strangely enough part of the solution was to close, the terminal running your simulator and closing xcode then reopening everything and rebuilding. So the process I followed was cd ios && rm -rf Pods && rm -rf podfile.lock && pod install Close xcode, simulator and terminal and reopen and rebuild.