最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

react native - Having an issue with expo: "ERROR TypeError: An error was thrown when attempting to render log messages

programmeradmin0浏览0评论

I am having an issue with log box and expo i tried to fix it but it was to no avail. here's the code. a little added comment: i am using a development server on android. i am trying to schedule a background task:

import * as BackgroundFetch from "expo-background-fetch";
import * as TaskManager from "expo-task-manager";
import { useState, useEffect } from "react";
import { fetchPrayerTimesFunction } from "../utils/FetchPrayerTimes";

const BACKGROUND_FETCH_TASK = "background-fetch";

TaskManager.defineTask(BACKGROUND_FETCH_TASK, async () => {
  try {
    const receivedNewData = await fetchPrayerTimesFunction();

    return receivedNewData
      ? BackgroundFetch.BackgroundFetchResult.NewData
      : BackgroundFetch.BackgroundFetchResult.NoData;
  } catch (error) {
    return BackgroundFetch.BackgroundFetchResult.Failed;
  }
});

export default function BackgroundFetchFunction() {
  const [isRegistered, setIsRegistered] = useState(false);
  const [status, setStatus] =
    useState<BackgroundFetch.BackgroundFetchStatus | null>(null);

  async function registerBackgroundFetchAsync() {
    return BackgroundFetch.registerTaskAsync(BACKGROUND_FETCH_TASK, {
      minimumInterval: 60 * 15, // 15 minutes
      stopOnTerminate: false, // android only,
      startOnBoot: true, // android only
    });
  }

  const checkStatusAsync = async () => {
    const status = await BackgroundFetch.getStatusAsync();
    const isRegistered = await TaskManager.isTaskRegisteredAsync(
      BACKGROUND_FETCH_TASK
    );
    setStatus(status);
    setIsRegistered(isRegistered);
  };

  useEffect(() => {
    registerBackgroundFetchAsync();
    checkStatusAsync();
    toggleFetchTask();
  }, []);

  const toggleFetchTask = async () => {
    if (!isRegistered) {
      await registerBackgroundFetchAsync();
    }

    checkStatusAsync();
  };
}

I was expecting for the background function to work but unfortunately it gave me a logbox error not sure why it did that as i have no console logs in there (unless im blind and i missed one)

与本文相关的文章

发布评论

评论列表(0)

  1. 暂无评论