jamesisaac / react-native-background-task

Periodic background tasks for React Native apps, cross-platform (iOS and Android), which run even when the app is closed.
MIT License
1.1k stars 110 forks source link

Native module cannot be null #10

Open Yamilquery opened 7 years ago

Yamilquery commented 7 years ago

When I import:

import BackgroundTask from 'react-native-background-task';

I get:

Native module cannot be null.

NativeEventEmitter
    NativeEventEmitter.js:31:16
<unknown>
    index.ios.js:3:44
loadModuleImplementation
    require.js:174:12
<unknown>
    index.ios.js:3
loadModuleImplementation
    require.js:174:12
<unknown>
    index.js:6
loadModuleImplementation
    require.js:174:12
<unknown>
    App.js:25
loadModuleImplementation
    require.js:174:12
<unknown>
    AppEntry.js:2
loadModuleImplementation
    require.js:174:12
guardedLoadModule
    require.js:119:45
global code
    <unknown file>:0
jamesisaac commented 7 years ago

Have you installed and linked the react-native-background-fetch library? As described in the installation steps: https://github.com/jamesisaac/react-native-background-task#ios

This library doesn't provide its own native module for iOS (it just proxies the other library), so any native module error is likely related to that library not being set up correctly.

shanakaf commented 6 years ago

stop the react packager and build the project (react-native run-ios) after installing the module. That solved my issue

Friis1978 commented 6 years ago

This is still an issue @jamesisaac

Could you perhaps provide some manual steps to make it work in iOs ?

There is no alternatives to use backgroundtasks elsewhere ?

jrnk commented 6 years ago

@Friis1978 and others, just follow the manual steps to link the react-native-background-fetch library here: https://github.com/transistorsoft/react-native-background-fetch/blob/master/docs/INSTALL-MANUAL-IOS.md

In my experience react-native link doesn't do a complete job 99% of the time.

Friis1978 commented 6 years ago

@jrnk Thank you very much, I will let you know if I can make it work, what I really want was to use it to make a tracking app run in the background, but if it can only make a task 1 time every 15 minute, I can not use it. What will you recommend me to use, if the task is for a tracking app ?

jrnk commented 6 years ago

@Friis1978 for iOS you can only do that if you set the background mode to listen for location updates, audio, ble etc, see the possible background modes here: https://developer.apple.com/documentation/uikit/core_app/managing_your_app_s_life_cycle/preparing_your_app_to_run_in_the_background/about_the_background_execution_sequence#overview

For Android you can do this with HeadlessJS: https://facebook.github.io/react-native/docs/headless-js-android.html

Friis1978 commented 6 years ago

@jrnk So I can use Background Fetch, and just enable location services from xCode, and use react-native-native-backgroundtask for android ? It seems to work well in android as it is.

jrnk commented 6 years ago

@Friis1978 unfortunately not, background fetch is only for what it says, networking in the background with a minimum of 15 min. You’d have to roll your own native module I’m afraid.

Friis1978 commented 6 years ago

@jrnk Ok thanks.

tahakhozooie commented 5 years ago

i have this problem too Native module cannot be null.

Zilleabbas10 commented 4 years ago
  1. Open project in Xcode.
  2. Go to build phases -> link binary with libraries
  3. Add libRNBackgroundFetch.a

It will resolve the above error.