Я прочитал документацию и попытался ее реализовать, но она не работает. Что я делаю не так? < /P>
Код: Выделить всё
import { Button } from '@react-native-material/core';
import { View } from 'react-native';
import BackgroundService from 'react-native-background-actions';
const sleep = (time:number) => new Promise((resolve) => setTimeout(() => resolve(), time));
const veryIntensiveTask = async (taskDataArguments:any) => {
console.log("in intensive task");
const { delay } = taskDataArguments;
await new Promise( async (resolve) => {
for (let i = 0; BackgroundService.isRunning(); i++) {
console.log(i);
await sleep(delay);
}
});
};
const options = {
taskName: 'Example',
taskTitle: 'ExampleTask title',
taskDesc: 'ExampleTask description',
taskIcon: {
name: 'ic_launcher',
type: 'mipmap',
},
color: '#ff00ff',
parameters: {
delay: 1000,
},
};
export default function Background(){
const startBackgoundJob=async ()=>{
await BackgroundService.start(veryIntensiveTask, options);
console.log("background service started");
};
const updateBackgroundJob=async ()=>{
await BackgroundService.updateNotification({taskDesc: 'New ExampleTask description'});
console.log("background service updated");
};
const stopBackgroundJob=async ()=>{
await BackgroundService.stop();
console.log("background service stopped");
};
return(
)
}
< /code>
Я пытался запустить это в эмуляторе с версиями Android SDKS 30 и 33, а на физическом устройстве, работающем SDK 33.
Я также удостоверился, что файл android manifest.xml < /code> содержит < /p>
Подробнее здесь: https://stackoverflow.com/questions/771 ... t-starting