更新依赖项版本,优化后台任务管理器,添加后台任务自动启动功能,调整后台获取配置,移除冗余代码

This commit is contained in:
richarjiang
2025-09-05 16:52:00 +08:00
parent 8d71d751d6
commit 6af86800f2
6 changed files with 428 additions and 541 deletions

View File

@@ -38,7 +38,7 @@ export class BackgroundTaskManager {
try {
// 配置后台获取
const status = await BackgroundFetch.configure({
minimumFetchInterval: 15, // 最小间隔15分钟iOS 实际控制间隔
minimumFetchInterval: 15, // 最小间隔15分钟单位:秒
}, async (taskId) => {
console.log('[BackgroundFetch] 后台任务执行:', taskId);
await this.executeBackgroundTasks();
@@ -53,6 +53,10 @@ export class BackgroundTaskManager {
this.isInitialized = true;
console.log('后台任务管理器初始化完成');
// 初始化完成后自动启动后台任务
await this.start();
console.log('后台任务已自动启动');
} catch (error) {
console.error('初始化后台任务管理器失败:', error);
throw error;
@@ -214,6 +218,11 @@ export class BackgroundTaskManager {
*/
async start(): Promise<void> {
try {
BackgroundFetch.scheduleTask({
taskId: 'com.anonymous.digitalpilates.backgroundfetch',
delay: 15 * 60 * 1000
});
await BackgroundFetch.start();
console.log('后台任务已启动');
} catch (error) {
@@ -410,31 +419,3 @@ export interface BackgroundTaskEvent {
success: boolean;
error?: string;
}
/**
* 后台任务配置选项
*/
export interface BackgroundTaskConfig {
minimumFetchInterval?: number;
stopOnTerminate?: boolean;
startOnBoot?: boolean;
enableHeadless?: boolean;
requiredNetworkType?: 'NONE' | 'ANY' | 'CELLULAR' | 'WIFI';
requiresCharging?: boolean;
requiresDeviceIdle?: boolean;
requiresBatteryNotLow?: boolean;
}
/**
* 默认后台任务配置
*/
export const DEFAULT_BACKGROUND_TASK_CONFIG: BackgroundTaskConfig = {
minimumFetchInterval: 15000, // 15分钟
stopOnTerminate: false,
startOnBoot: true,
enableHeadless: true,
requiredNetworkType: 'ANY',
requiresCharging: false,
requiresDeviceIdle: false,
requiresBatteryNotLow: false,
};