Skip to content

Commit 434242d

Browse files
Added findEvent by ID (iOS)
1 parent ff1b9b6 commit 434242d

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ Basic operations, you'll want to copy-paste this for testing purposes:
199199
// if you need to find events in a specific calendar, use this one. All options are currently ignored when finding events, except for the calendarName.
200200
var calOptions = window.plugins.calendar.getCalendarOptions();
201201
calOptions.calendarName = "MyCreatedCalendar"; // iOS only
202+
calOptions.id = "D9B1D85E-1182-458D-B110-4425F17819F1"; // iOS only, get it from createEventWithOptions (if not found, we try matching against title, etc)
202203
window.plugins.calendar.findEventWithOptions(title,eventLocation,notes,startDate,endDate,calOptions,success,error);
203204

204205
// list all events in a date range (only supported on Android for now)

plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
xmlns="http://apache.org/cordova/ns/plugins/1.0"
44
xmlns:android="http://schemas.android.com/apk/res/android"
55
id="nl.x-services.plugins.calendar"
6-
version="4.3.6-dev">
6+
version="4.3.6">
77

88
<name>Calendar</name>
99

src/ios/Calendar.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ -(void)findEventWithOptions:(CDVInvokedUrlCommand*)command {
683683

684684
// actually the only option we're currently using is calendarName
685685
NSDictionary* calOptions = [options objectForKey:@"options"];
686+
NSString* calEventID = [calOptions objectForKey:@"id"];
686687
NSString* calendarName = [calOptions objectForKey:@"calendarName"];
687688

688689
NSTimeInterval _startInterval = [startTime doubleValue] / 1000; // strip millis
@@ -708,7 +709,18 @@ -(void)findEventWithOptions:(CDVInvokedUrlCommand*)command {
708709
}
709710
}
710711

711-
NSArray *matchingEvents = [self findEKEventsWithTitle:title location:location notes:notes startDate:myStartDate endDate:myEndDate calendar:calendar];
712+
// Find matches
713+
EKCalendarItem *theEvent;
714+
if (calEventID != nil) {
715+
theEvent = [self.eventStore calendarItemWithIdentifier:calEventID];
716+
}
717+
718+
NSArray *matchingEvents;
719+
if (theEvent == nil) {
720+
matchingEvents = [self findEKEventsWithTitle:title location:location notes:notes startDate:myStartDate endDate:myEndDate calendar:calendar];
721+
} else {
722+
matchingEvents = [NSArray arrayWithObject:theEvent];
723+
}
712724
NSMutableArray * eventsDataArray = [self eventsToDataArray:matchingEvents];
713725
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus: CDVCommandStatus_OK messageAsArray:eventsDataArray];
714726
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];

0 commit comments

Comments
 (0)