diff --git a/package.json b/package.json index 683fa136..981eca70 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cordova-plugin-calendar", - "version": "4.4.5", + "version": "4.4.6", "description": "This plugin allows you to manipulate the native calendar.", "cordova": { "id": "cordova-plugin-calendar", diff --git a/src/android/nl/xservices/plugins/Calendar.java b/src/android/nl/xservices/plugins/Calendar.java index a7f23cc2..6b3826a9 100644 --- a/src/android/nl/xservices/plugins/Calendar.java +++ b/src/android/nl/xservices/plugins/Calendar.java @@ -451,7 +451,7 @@ public void run() { } private static String getPossibleNullString(String param, JSONObject from) { - return from.isNull(param) ? null : from.optString(param); + return from.isNull(param) || "null".equals(from.optString(param)) ? null : from.optString(param); } private void listEventsInRange(JSONArray args) { diff --git a/src/android/nl/xservices/plugins/accessor/AbstractCalendarAccessor.java b/src/android/nl/xservices/plugins/accessor/AbstractCalendarAccessor.java index 38f05efd..eb0359df 100644 --- a/src/android/nl/xservices/plugins/accessor/AbstractCalendarAccessor.java +++ b/src/android/nl/xservices/plugins/accessor/AbstractCalendarAccessor.java @@ -205,8 +205,8 @@ private Event[] fetchEventInstances(String title, String location, long startFro if (!"".equals(selection)) { selection += " AND "; } - selection += Events.EVENT_LOCATION + "=?"; - selectionList.add(location); + selection += Events.EVENT_LOCATION + " LIKE ?"; + selectionList.add("%" + location + "%"); } String[] selectionArgs = new String[selectionList.size()]; diff --git a/src/ios/Calendar.m b/src/ios/Calendar.m index 156ebba5..f38a37c4 100644 --- a/src/ios/Calendar.m +++ b/src/ios/Calendar.m @@ -9,22 +9,18 @@ @implementation Calendar @synthesize eventStore; @synthesize interactiveCallbackId; -#pragma mark Initialisation functions +#pragma mark Initialization functions -- (CDVPlugin*) initWithWebView:(UIWebView*)theWebView { - self = (Calendar*)[super initWithWebView:theWebView]; - if (self) { +- (void) pluginInitialize { [self initEventStoreWithCalendarCapabilities]; - } - return self; } - (void) initEventStoreWithCalendarCapabilities { __block BOOL accessGranted = NO; - eventStore= [[EKEventStore alloc] init]; - if([eventStore respondsToSelector:@selector(requestAccessToEntityType:completion:)]) { + EKEventStore* eventStoreCandidate = [[EKEventStore alloc] init]; + if([eventStoreCandidate respondsToSelector:@selector(requestAccessToEntityType:completion:)]) { dispatch_semaphore_t sema = dispatch_semaphore_create(0); - [eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { + [eventStoreCandidate requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error) { accessGranted = granted; dispatch_semaphore_signal(sema); }]; @@ -32,9 +28,9 @@ - (void) initEventStoreWithCalendarCapabilities { } else { // we're on iOS 5 or older accessGranted = YES; } - + if (accessGranted) { - self.eventStore = eventStore; + self.eventStore = eventStoreCandidate; } } @@ -313,11 +309,11 @@ - (NSArray*) findEKEventsWithTitle: (NSString *)title } if (location != (id)[NSNull null] && location.length > 0) { location = [location stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"]; - [predicateStrings addObject:[NSString stringWithFormat:@"location == '%@'", location]]; + [predicateStrings addObject:[NSString stringWithFormat:@"location contains[c] '%@'", location]]; } if (notes != (id)[NSNull null] && notes.length > 0) { notes = [notes stringByReplacingOccurrencesOfString:@"'" withString:@"\\'"]; - [predicateStrings addObject:[NSString stringWithFormat:@"notes == '%@'", notes]]; + [predicateStrings addObject:[NSString stringWithFormat:@"notes contains[c] '%@'", notes]]; } NSString *predicateString = [predicateStrings componentsJoinedByString:@" AND "]; @@ -891,34 +887,42 @@ - (void) eventEditViewController:(EKEventEditViewController*)controller didCompl [self.commandDelegate sendPluginResult:pluginResult callbackId:self.interactiveCallbackId]; } + +/* There is no distingtion between read and write access in iOS */ - (void)hasReadPermission:(CDVInvokedUrlCommand*)command { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:YES]; + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:(self.eventStore != nil)]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } - (void)requestReadPermission:(CDVInvokedUrlCommand*)command { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:[self requestCalendarAccess]]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } - (void)hasWritePermission:(CDVInvokedUrlCommand*)command { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:YES]; + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:(self.eventStore != nil)]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } - (void)requestWritePermission:(CDVInvokedUrlCommand*)command { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:[self requestCalendarAccess]]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } - (void)hasReadWritePermission:(CDVInvokedUrlCommand*)command { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:YES]; + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsBool:(self.eventStore != nil)]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } - (void)requestReadWritePermission:(CDVInvokedUrlCommand*)command { - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; + CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:[self requestCalendarAccess]]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } +-(CDVCommandStatus)requestCalendarAccess{ + [self initEventStoreWithCalendarCapabilities]; + return (self.eventStore != nil) ? CDVCommandStatus_OK : CDVCommandStatus_ERROR; +} + + @end