首页 > 解决方案 > 背景提取:无法读取未定义的属性“配置”

问题描述

我一直在尝试集成transistorsoft background-fetch 库但没有成功: https ://github.com/transistorsoft/react-native-background-fetch

当我将任何方法链接到 BackgroundFetch 组件时,我得到了错误(附在这篇文章中)

import BackgroundFetch from "react-native-background-fetch";

class TimerScreen extends React.Component {

...

componentDidMount() {

    this.configureBackgroundFetch();

}
...
configureBackgroundFetch() {
    // Configure BackgroundFetch.
    BackgroundFetch.configure({
      minimumFetchInterval: 15, // <-- minutes (15 is minimum allowed)
      stopOnTerminate: false, // <-- Android-only,
      startOnBoot: true, // <-- Android-only
      enableHeadless: true
    }, async () => {
      console.log('BackgroundFetch has started');
      BackgroundFetch.finish(BackgroundFetch.FETCH_RESULT_NEW_DATA);
    }, (error) => {
      console.log('RNBackgroundFetch failed to start')
    });
}
...

我一直无法找出图书馆为什么不工作。我使用了 react native 链接并将其安装在 package.json

 ...
 {
       ...
       "react-native-background-fetch": "^2.5.3",
       ...
 }
 ...

标签: react-nativebackground-fetch

解决方案


该问题是由于 Expokit 未正确配置为使用本机模块引起的。我制作了一个简单的 React Native 应用程序,并且该库可以正常工作而没有返回错误。


推荐阅读