-
-
Notifications
You must be signed in to change notification settings - Fork 102
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
Possibility to add an alert for iOS #58
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -53,6 +53,7 @@ - (NSDictionary *)constantsToExport | |
static NSString *const _notes = @"notes"; | ||
static NSString *const _url = @"url"; | ||
static NSString *const _allDay = @"allDay"; | ||
static NSString *const _alert = @"alert"; | ||
|
||
static NSString *const MODULE_NAME= @"AddCalendarEvent"; | ||
|
||
|
@@ -272,6 +273,33 @@ - (EKEvent *)createNewEventInstance { | |
if (options[_allDay]) { | ||
event.allDay = [RCTConvert BOOL:options[_allDay]]; | ||
} | ||
if (options[_alert]) { | ||
NSDate *originalDate = [RCTConvert NSDate:options[_startDate]]; | ||
|
||
if ([[RCTConvert NSString:options[_alert]] caseInsensitiveCompare:@"0"] == NSOrderedSame) | ||
{ | ||
EKAlarm * alarm = [EKAlarm alarmWithAbsoluteDate:originalDate]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you're using
I think this might be useful. |
||
event.alarms = @[alarm]; | ||
} | ||
if ([[RCTConvert NSString:options[_alert]] caseInsensitiveCompare:@"1"] == NSOrderedSame) | ||
{ | ||
NSDate *alertReminder = [originalDate dateByAddingTimeInterval:-60*5]; | ||
EKAlarm * alarm = [EKAlarm alarmWithAbsoluteDate:alertReminder]; | ||
event.alarms = @[alarm]; | ||
} | ||
if ([[RCTConvert NSString:options[_alert]] caseInsensitiveCompare:@"2"] == NSOrderedSame) | ||
{ | ||
NSDate *alertReminder = [originalDate dateByAddingTimeInterval:-60*30]; | ||
EKAlarm * alarm = [EKAlarm alarmWithAbsoluteDate:alertReminder]; | ||
event.alarms = @[alarm]; | ||
} | ||
if ([[RCTConvert NSString:options[_alert]] caseInsensitiveCompare:@"3"] == NSOrderedSame) | ||
{ | ||
NSDate *alertReminder = [originalDate dateByAddingTimeInterval:-60*60]; | ||
EKAlarm * alarm = [EKAlarm alarmWithAbsoluteDate:alertReminder]; | ||
event.alarms = @[alarm]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. take a good look at the code: there is a lot of duplicates - the ifs look more or less the same, with just small differences. It would be better to remove the duplications and perhaps extract this functionality into a separate function :) |
||
} | ||
} | ||
return event; | ||
} | ||
|
||
|
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.
The options "0" ... "3" seem rather random - why not just pass the number of minutes from the JS side?
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.
Ahh, yeah I was quite agree but because I didn't see that react-native-calendar-events already managed that. I'll have a look to see how I can eventually implement it here ! Thank's !