-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Implemented daily notification with custom time #33
Conversation
523c1bb
to
7f57d12
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I've left some comments on what I'd say should be changed. Also need to update the rescheduleNotifications()
method in FlutterLocalNotificationsPlugin.java. That method is called when a device has been rebooted. Anything scheduled via the alarm manager is wiped out when the device has been turned off.
Once you've done the iOS side. I'll take a look and see if I can test out your fork before I'll merge it in. Also I've no problem with hardcoding the time in the example app as it's just for demonstration purposes so you'd need to do that anyway :)
lib/flutter_local_notifications.dart
Outdated
{String payload}) async { | ||
Map<String, dynamic> serializedPlatformSpecifics = | ||
_retrievePlatformSpecificNotificationDetails(notificationDetails); | ||
await _channel.invokeMethod('periodicallyShow', <String, dynamic>{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
invokeMethod should pass in 'showDailyAtTime' for better separation. This means that the onMethodCall override on the native side will need a different case to handle what needs to be done. If you could also split up repeatNotification to two separate methods (one for interval-based, the other for time-based) then that would be good as well
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have chosen this approach because I considered this feature as a Daily periodicallyShow
use case, that way changes in both Java and Objective-C remain minimal. I can add that change though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Valid point, however from the Dart side they're separate methods so from a maintainability perspective, I think it's better to separate it out as it makes mapping between the Java/Objective C and Dart more obvious
lib/flutter_local_notifications.dart
Outdated
|
||
Time([this.hour = 0, this.minute = 0, this.second = 0]); | ||
|
||
Map<String, int> get serialized => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you could make this a toMap() method to be consistent with the rest of the code then that would be great as reading something like time.serialized
feels awkward
lib/flutter_local_notifications.dart
Outdated
final int minute; | ||
final int second; | ||
|
||
Time([this.hour = 0, this.minute = 0, this.second = 0]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there should be some validation here to restrict the accepted values, possibly through assert statements. Should add documentation as well through comments but you can leave that for me to do
fixed bad time constructor Fixed param name, suppresed warning Better notification body
Yep I took a look and it looks about right but will need some of the changes I commented about earlier regarding the string that's passed from Dart side via the invokeMethod call. I think once all the changes are made, we're good to merge it. I'll then do some clean up and testing before publishing a new version. Thanks for your contribution btw. I've just realised that I've been using your JSON to Dart tool. Super handy and I've asked on the Flutter repo about putting a link to your site but go no response :S |
Added support for IOS
46b551b
to
1b784e5
Compare
I've made the requested changes to the Dart's Time class. I'll make the other changes tomorrow. Glad that my Dart to JSON tool is helping others |
I've added a weekday bitwise flag option. I haven't test it though but I will tonight |
By that are you referring to the ability to just have notifications displayed on weekdays only? If so then I don't think that works for the user notifications framework on iOS with the date components as you'd have to create a separate notification for each day, which means each one has their own ID. On that note, i think it'll be possible to schedule a notification to fire on a specified a day of the week and time but that's a separate discussion :) |
In android it was easy, you just schedule a notification every day and when the intent is fired you just choose not to fire the notification. In IOS things are a bit mor complicated, you have to schedule one notification for each day. My first solution is to provide the first notification ID and then increment the number internally. But that solution is really ugly because the plugin user would have to calculate the new notifications id. This is just a proof of concept. If it works I would generate the notification id with some uuid or the unix timestamp and return an array of ids. That of course would break the default API usage because there would be a single function that does generate the ids for you but the others won't. It would be up to you to accept that change or not and I would understand if you don't want that change in your project. In that case I would create a plugin of my own and publish it because I need weekdays notifications for my project :) |
Yeah I had a feeling Android would be easier and that it would be more harder on iOS. I would say leave that for the moment and if you could make the other changes then we can merge this PR in. Looking at how to do it for weekdays can be done in a separate PR or something I can look into even |
Ok, let me wrap up what I got and finish this PR tonight (It's 19:45 Argentina so I guess that I would finish this in a couple of hours) |
Cheers mate. I should have some bandwidth to look into the weekday one and touched on the rough idea i've got for it :) |
Done, I've created a custom name for the new channel method and reverted the changes on the weekdays. I've created a new branch on my fork with my work on weekdays notification. I'll leave that branch for you to check the code. Since I need to send notifications on weekdays for my app, I'have to create my own plugin to do that. I prefer swift over Objective C but probably I will reusing some parts of this project and I'll mention you and your project as well in the library that I'm creating. Let me know if you need anything. Cheers |
Np, I should be able to merge your changes later. I do prefer Swift as well except I originally ran into issues with debugging in Swift. I heard there use to be issues with plugins written in Swift that were consumed by apps where the iOS head project is in Objective C. Not sure if that issue still exists as it's not something I've been monitoring |
fyi, i've uploaded a new version that includes your changes with fixes I made. Also added ability to show a weekly notification on a specific day and time that you could also use to solve your problem for showing notifications on weekdays |
I've implemented it for android, I'll try to make it work for IOS as well
Caveat: The notification time is hardcoded in the example app