如何在 Android 8.1 (Oreo) 的 React Native 中执行后台作业



我已经编写了代码,用于使用 react-native-background-job 从服务器检索通知,以防应用程序在后台或已被杀死。该代码适用于所有其他版本的Android,但不适用于Android 8.1。它没有运行,并且还会抛出弹出通知"您的应用程序已关闭,重新启动,发送反馈"。我知道这是因为奥利奥对应用程序后台运行的执行限制施加了限制。我应该对代码进行哪些更改才能使其在 Android 8.1 上运行?

const regularJobKey = 'regularJobKey';
let uid = 0; let id = 0;  
const checking = () => {
axios.get('/getmessagecount').then(response => {
...
});
};  
BackgroundJob.register({    
jobKey: regularJobKey,  
job: () => checking()  
});
export default class App extends Component {      
componentWillMount = () => {     
BackgroundJob.schedule({  
jobKey: regularJobKey,  
period: 20000,  
alwaysRunning: true  
});  
}
}

我在这里找到了这个问题的答案——> https://github.com/vikeri/react-native-background-job/commit/dd20672c6719a2eb4739161ee1f52386c4fa0f70?diff=split

最新更新