Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with Scheduling Alarms Using alarm Package in Background Tasks with work_manager #584

Open
4 tasks done
Luqmanasif6 opened this issue Dec 30, 2024 · 0 comments
Open
4 tasks done
Labels
bug Something isn't working

Comments

@Luqmanasif6
Copy link

  • I have read the README
  • I have done the setup for Android
  • I have done the setup for iOS
  • I have ran the sample app and it does not work there

Version

Technology Version
Workmanager version latest
Xcode version latest
Swift version latest
iOS deployment target greater than 14.0

Describe the error
I am facing an issue while trying to schedule alarms using the alarm package within a work_manager background task. The task to schedule alarms works correctly when executed in the foreground, but when executed in the background, it fails to schedule alarms. The issue seems to occur at the line:

Dart code:
final result = await Alarm.set(alarmSettings: alarmSettings);

Steps to Reproduce:
Use the work_manager package to execute a background task.
Inside the background task, try scheduling an alarm using the alarm package with the following settings:

Dart code:
final alarmSettings = AlarmSettings(
id: 67,
dateTime: DateTime.now().add(Duration(seconds: 10)),
assetAudioPath: 'assets/audio/azan.mp3',
loopAudio: true,
vibrate: true,
fadeDuration: 3.0,
warningNotificationOnKill: Platform.isIOS,
androidFullScreenIntent: true,
notificationSettings: const NotificationSettings(
title: 'Prayer Notification',
body: 'Time for prayer!',
stopButton: 'Stop Alarm',
icon: 'notification_icon',
),
);
final result = await Alarm.set(alarmSettings: alarmSettings);
The alarm fails to schedule when the task is executed in the background.
Expected Behavior:
The alarm should be scheduled correctly even when the task is running in the background.

Actual Behavior:
The Alarm.set() method does not successfully schedule the alarm when executed in the background. The program execution is blocked, and no error or output is produced in the console.

Environment:
Platform: Android / iOS (specify which platform you are using)
Flutter Version: latest
alarm Package Version: 4.1.1
work_manager Package Version: [Your work_manager version]
OS Version: [Android version / iOS version]

Additional Information:
I've tried using try-catch blocks around the Alarm.set() method, but it doesn't seem to catch any errors.
The issue occurs specifically when trying to run background tasks with work_manager.
I have also verified that the necessary permissions are granted for background tasks and notifications.
The alarm works as expected in the foreground but not in the background.

Possible Cause:
It appears that the alarm package does not properly handle alarm scheduling when executed in a background task on certain platforms, particularly Android and iOS.

Request:
Could you investigate and provide any guidance or solutions on how to reliably schedule alarms using the alarm package in background tasks with the work_manager package?

@Luqmanasif6 Luqmanasif6 added the bug Something isn't working label Dec 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant