我使用XCode保存事件并保存正常。保存也返回一个ID。
当我尝试获取日历的所有事件,然后逐个访问事件的ID时,它总是nil
保存代码:
-(NSNumber*) save:(id)arg
{
id val = nil;
ENSURE_ARG_OR_NIL_AT_INDEX(val, arg, 0, NSNumber);
EKSpan span = EKSpanThisEvent;
if (val != nil) {
span = [TiUtils intValue:val def:EKSpanThisEvent];
}
EKEventStore* ourStore = [module store];
if (ourStore == NULL) {
DebugLog(@"Could not save event, missing Event Store");
return NUMBOOL(NO);
}
EKEvent* currEvent = [self event];
if (currEvent == NULL) {
DebugLog(@"event is missing");
return NUMBOOL(NO);
}
__block NSError * error = nil;
__block BOOL result;
TiThreadPerformOnMainThread(^{
result = [ourStore saveEvent:currEvent span:span commit:YES error:&error];
}, YES);`enter code here`
if (result == NO || error != nil) {
[self throwException:[NSString stringWithFormat:@"Failed to save event : %@",[TiUtils messageFromError:error]]
subreason:nil
location:CODELOCATION];
}
return NUMBOOL(result);
}
Retreive Code:
- (NSArray *)_fetchAllEventsbetweenDate:(NSDate *)date1 andDate:(NSDate *)date2
{
if (![NSThread isMainThread]) {
__block id result = nil;
TiThreadPerformOnMainThread(^{
result = [[self _fetchAllEventsbetweenDate:date1 andDate:date2] retain];
},
YES);
return [result autorelease];
}
EKEventStore *ourStore = [self ourStore];
if (ourStore != nil) {
NSPredicate *predicate = [ourStore predicateForEventsWithStartDate:date1
endDate:date2
calendars:[NSArray arrayWithObject:[self calendar]]];
return [ourStore eventsMatchingPredicate:predicate];
}
return NULL;
}