小编sim*_*tar的帖子

无法让后台任务在 React-Native 中工作

我需要经常写入文本文件,假设在 iOS 和 android 中使用 react-native 将时间戳写入文件。我在以下库的帮助下编写了一个应用程序。在 android 上,该应用程序运行良好,但在iOS 上运行不正常。

我尝试使用这些库:

  1. 反应原生背景任务
  2. 反应原生背景获取
  3. 反应原生背景队列 + 反应原生背景任务

但它们都不能正常工作:

  1. 使用 react-native-background-task:文件每天随机写入 5-6 次或更少
  2. 使用 react-native-background-fetch:文件每天随机写入 3-4 次或更少
  3. react-native-background-queue + react-native-background-task:文件根本没有写!

请您告诉我这些行为是否正常,如果不正常,我做错了什么???

任何帮助将不胜感激。

这是我的代码:

为了使用react-native-background-task

import React from 'react'
import Mytest from './test';
import BackgroundTask from 'react-native-background-task'
import {
    Text,
    View,
  } from 'react-native';

BackgroundTask.define(() => {
  console.log('Hello from a background task')
  Mytest.writeFiles()
  BackgroundTask.finish()
})

export default class MyApp extends React.Component {

  componentDidMount() {
    BackgroundTask.schedule()
  }

  render() {
    return( …
Run Code Online (Sandbox Code Playgroud)

android background-process ios react-native

6
推荐指数
0
解决办法
1447
查看次数

标签 统计

android ×1

background-process ×1

ios ×1

react-native ×1