gdelataillade / alarm

A Flutter plugin to easily manage alarms on iOS and Android
https://pub.dev/packages/alarm
MIT License
132 stars 86 forks source link

[HELP & QUESTION] How to connect native code and alarm package #168

Closed isaaclkh closed 8 months ago

isaaclkh commented 8 months ago

Is your feature request related to a problem? Please describe.

This package doesn't have a problem. (Thank you for this wonderful package) I have a question that is there a way to listen to the alarm stream in the native code? Currently, I'm making a project that rings alarm and sends an email to specific user at the time. Sending an email also needs to work in when the application status is background. Android has no problem, but iOS needs to connect native code with flutter.

So, how can I listen to the ring stream in native? Is it possible to do that?


Describe the solution you'd like

I briefly reviewed the swift code that were made in this package. Since, I'm not a native coder, it was kind of tricky to understand. Just a few hints or recommendations are appreciated. Thank you in advance.


Describe alternatives you've considered

Any kind of help means a lot to me. Please help me... 🥲


Additional context

Thank you

gdelataillade commented 8 months ago

Hi @isaaclkh

Thanks for your interest in the plugin !

In iOS, if you need to call native code when app is in the background, you will have to call it from my AlarmSwiftPlugin class, like you said. The method executed when alarm starts to ring is handleAlarmAfterDelay, line 239.

I think what you should do is to fork my alarm plugin and add your email feature at the end of handleAlarmAfterDelay function. In order to have access to user's email, you could pass it as parameter all the way down to handleAlarmAfterDelay.

However, iOS does not allow sending emails in the background without user interaction due to privacy and security reasons, so you may have to do it server-side (send a request to your server and it will send the email). Another option could be to use background fetch or silent push notifications to wake your app periodically and check if there are any emails to be sent.

Let me know if you have any question. I'm closing this issue because it is not directly related to the plugin but I will keep answering here to help you if I can.

isaaclkh commented 8 months ago

Thank you! I'll try 😁