I need to run a task at a specific time (for example 2 hours later) in Flutter, something like an alarm, I have searched in flutter and I know that this is not possible easily.
I have tested work manager and it didn't work properly. I have done the Android Part of the project with Platform_channel and Android Alarm Manager .
I was wondering If you know any other ways in IOS (or Flutter if possible).
EDIT :
My App needs to play a sound (1~3 minutes length) at specific time something like an alarm.
One option for scheduling a task to run at a specific time in Flutter on iOS is to use the AlarmManager class from the flutter_local_notifications plugin.
Here is an example of how to schedule a task to run 2 hours later:
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
final alarmManager = AlarmManager();
// Do it like this
final scheduledTime = DateTime.now().add(Duration(hours: 2));
alarmManager.scheduleAlarm(
scheduledTime,
AlarmNotification(
title: 'Task',
body: 'Task that you scheduled to run 2 hours later',
),
);
I would check out this question and answer Local notification sound not playing while app in background - Swift . It's not exactly the same as your question but I think you could use the same technique with a little creativity.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.