Rapsssito / react-native-background-actions

React Native background service library for running background tasks forever in Android & iOS.
MIT License
818 stars 117 forks source link

The background task doesn't runs on iOs simulator #207

Closed AngelRmrz closed 7 months ago

AngelRmrz commented 10 months ago

I got this custom hook, to handle the download of some images, however i was trying to apply the example on the docs with some tweaks, but on the iOs simulator just doesn't run, the app doesn't crash or something weird, the background notification just doesn't shows but the task executes right.

Here's my custom hook:

import { useApolloClient } from '@apollo/client';
import { useState } from 'react';
import BackgroundService from 'react-native-background-actions';

export interface DownloadProgress {
    total: number;
    completed: number;
}

export const useDownload = (
    ebookId: string,
    indiceId: string,
    oasList: string[],
    version: string,
) => {
    const client = useApolloClient();
    const [downloadStatus, setDownloadStatus] = useState<DownloadProgress>({
        total: oasList.length,
        completed: 0,
    });

    const handleDownload = async () => {
        await BackgroundService.start(
            async () => {
                try {
                    console.log('Downloading', oasList);
                    const timer = setTimeout(() => {
                        BackgroundService.stop();
                    }, 5000);
                    return new Promise<void>((resolve) => {
                        clearTimeout(timer);
                        resolve();
                    });
                } catch (e) {
                    console.error(e);
                }
            },
            {
                taskName: 'Descargando progresion',
                taskTitle: 'Descargando',
                taskDesc: 'Se esta descargando la progresion',
                taskIcon: {
                    name: 'ic_launcher',
                    type: 'mipmap',
                },
                linkingURI: 'technomizeEMS://',
            },
        );
    };

    return {
        handleDownload,
    };
};

Here's the npx react-native info command output:

System:
  OS: macOS 14.2.1
  CPU: (8) arm64 Apple M2
  Memory: 428.88 MB / 16.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.18.2
    path: ~/.nvm/versions/node/v18.18.2/bin/node
  Yarn:
    version: 1.22.19
    path: ~/.nvm/versions/node/v18.18.2/bin/yarn
  npm:
    version: 9.8.1
    path: ~/.nvm/versions/node/v18.18.2/bin/npm
  Watchman:
    version: 2023.10.09.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.2
    path: /opt/homebrew/bin/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.2
      - iOS 17.2
      - macOS 14.2
      - tvOS 17.2
      - watchOS 10.2
  Android SDK: Not Found
IDEs:
  Android Studio: 2022.3 AI-223.8836.35.2231.10811636
  Xcode:
    version: 15.1/15C65
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 11.0.21
    path: /usr/bin/javac
  Ruby:
    version: 2.6.10
    path: /usr/bin/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react:
    installed: 18.2.0
    wanted: 18.2.0
  react-native:
    installed: 0.72.6
    wanted: 0.72.6
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

If somebody knows any solution it will be appreciated, thanks.