Skip to content

compiling Ultimate Alarm Clock on iOS #726

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

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

kushchoudhary98
Copy link
Contributor

@kushchoudhary98 kushchoudhary98 commented Mar 4, 2025

Description

This PR is all about creating the iPhone version of Ultimate Alarm Clock.

Proposed Changes

  • fixed dependency issues for both platforms(android & ios) [mobile_scanner: 3.5.5 -> 5.1.0].
  • resolved errors while building the app(such as adding compiler flags, and increasing IPHONEOS_DEPLOYMENT_TARGET to 15.5).
  • fixed error: MissingPluginException (added methodChannel to the native side).
  • added alarm scheduling logic [using FMDB(Wrapper around SQLite database), all alarms are fetched from the SQLite database and the latest alarm is scheduled].
  • alarm-dismiss window now appears.

Screenshots

Screen.Recording.2025-03-06.at.10.07.59.PM.mov

Screenshot 2025-03-06 at 10 09 22 PM

Checklist

  • Tests have been added or updated to cover the changes
  • Documentation has been updated to reflect the changes
  • Code follows the established coding style guidelines
  • All tests are passing

@kushchoudhary98 kushchoudhary98 marked this pull request as ready for review March 6, 2025 17:00
@kushchoudhary98 kushchoudhary98 marked this pull request as draft March 9, 2025 10:45
@kushchoudhary98 kushchoudhary98 marked this pull request as ready for review March 20, 2025 16:57
@kushchoudhary98
Copy link
Contributor Author

Research done up untill now:

What works:

  • Stopwatch
  • Timer
  • Basic Alarm Functionality (with a catch!)

How does Alarm Scheduling works(for now)?

Whenever the user add an alarm:

  • On the Flutter side: The usual stuff happens as it did before(nothings changed there).The alarm
    model is created and it is saved on both ISAR & SQLite database. scheduleAlarm method
    channel is called to handle scheduling on the native iOS side.
  • On the native iOS side: When the scheduleAlarm channel is called, all the alarms currently in
    the SQLite database are fetched and the latest alarm is selected for scheduling. All pending
    alarms are cancelled. Then, ‘scheduleNotification’ function is called which schedules 60
    notification with a gap of 5 seconds. And with 5 seconds of notification sound, it gives us about
    (60*5)/60 = 5 minutes of continuous alarm like effect(alarm rings for 5 minutes straight until
    dismissed).

Why is the Alarm functionality so basic?

This has all to do with how iOS manages apps in the background [refer]
All the advanced functionality of the app can work only if the app can be launched in the background
at a specific time(the scheduled alarm time).
Below are all the different things that I researched:

  • Automation: Shortcuts & Personal Automation requires manual configuration.
    • Personal Automations: They cannot be created programmatically; user has to create them manually (it will not be ideal to have user do this for every alarm)
    • Shortcuts: They only run one at a time and requires the user to start them manually.
  • Audio: Yes. This one can solve all our problems. The app could just play silent audio in the
    background, and iOS will not interfere with its background execution, hence, keeping it in
    the background forever. There is another app(Alarmy) that does the same. According to the
    devs [refer] , it plays a silent audio of 1 second in every 9 seconds, which is just enough to keep
    the app running in the background.
    But there is a catch: since the app stays active in the background, it drains a lot of battery
    [refer] , and might not be an ideal solution.
  • BGTaskScheduler: This allows the app to be launched in the background so that it can
    perform certain background tasks, like syncing messages, updating weather information, etc.
    But there is a catch: the Apple iOS system is the one that decides whether to run the background
    task or maybe delay its execution.
    There are two types of tasks: BGAppRefreshTask and BGProcessingTask
    • For BGProcessingTask, it is strictly written in the apple’s documentation that this task can
      be interrupted by the system. And also, these type of tasks are mainly run during the night when
      iPhone is charging [refer] .
    • For BGAppRefreshTask, I tried it, on a real iPhone, since iOS simulators cannot produce
      exact environments(like, phone usage, battery condition, user activity) for system to know
      whether to interrupt the app’s background task. And it came out to be very unpredictable and
      there may be cases when alarm will not ring at the specified time [refer] .
  • AlarmKit: Nope, this one does not work in the background. So, not a chance.
  • Alarm (Flutter package): Plays silent audio in background all the time. This does keep the
    app alive in the background but as we already know, Battery Drainage issue will be there.
  • EKAlarm (EventKit): Used for interacting with the system calendar, to set reminders. Which
    is also a simple notification alert, nothing more than that. Not what we need.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant