Skip to content

Commit

Permalink
merge upstream 4.4.6
Browse files Browse the repository at this point in the history
  • Loading branch information
EddyVerbruggen committed Jan 11, 2016
2 parents a81bef1 + c08426d commit b94c5a1
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 23 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/android/nl/xservices/plugins/Calendar.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()];
Expand Down
42 changes: 23 additions & 19 deletions src/ios/Calendar.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,32 +9,28 @@ @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);
}];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
} else { // we're on iOS 5 or older
accessGranted = YES;
}

if (accessGranted) {
self.eventStore = eventStore;
self.eventStore = eventStoreCandidate;
}
}

Expand Down Expand Up @@ -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 "];
Expand Down Expand Up @@ -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

0 comments on commit b94c5a1

Please sign in to comment.