0

カレンダーから ekevents をフェッチし ( EKEventStore によってpredicateForEventsWithStartDate:endDate:calendars:)、app-events をカレンダーと同期する ( を使用) アプリケーションを構築しますEKEventStore saveEvent:span:commit:error:

への静的参照を使用し、異なるプロセスが に同時にアクセスしないEKEventStoreようにします。EKEventStore

IOS7 で Springboard がクラッシュすると、アプリが終了することがあります。これがクラッシュのバックトレースです。

Last Exception Backtrace:
0   CoreFoundation                  0x18625e950 __exceptionPreprocess + 132
1   libobjc.A.dylib                 0x1927641fc objc_exception_throw + 60
2   CoreFoundation                  0x18625e810 +[NSException raise:format:arguments:] +     116
3   Foundation                      0x186d96db4 -[NSAssertionHandler     handleFailureInMethod:object:file:lineNumber:description:] + 112
4   EventKit                        0x186adab84 -[EKEventStore _addFetchedObjectWithID:] + 240
5   EventKit                        0x186adaa64 __78-[EKEventStore registerFetchedObjectWithID:withDefaultLoadedProperties:inSet:]_block_invoke + 96
6   libdispatch.dylib               0x192d3bfd4 _dispatch_client_callout + 16
7   libdispatch.dylib               0x192d41c84 _dispatch_barrier_sync_f_invoke + 48
8   EventKit                        0x186ada990 -[EKEventStore     registerFetchedObjectWithID:withDefaultLoadedProperties:inSet:] + 148
9   EventKit                        0x186ae1458 __41-[EKPredicateSearch startWithCompletion:]_block_invoke + 796
10  EventKit                        0x186ae1050 -[EKDaemonConnection _processReplyWithID:data:finished:] + 220
11  EventKit                        0x186ae0f5c CADReceiveReply + 136
12  EventKit                        0x186ae0eac _XReply + 124
13  EventKit                        0x186ae0e04 ClientCallbacks_server + 100
14  libdispatch.dylib               0x192d3fae8 dispatch_mig_server + 352
15  EventKit                        0x186ae0d6c __43-[EKDaemonConnection initWithOptions:path:]_block_invoke16 + 44
16  libdispatch.dylib               0x192d3bfd4 _dispatch_client_callout + 16
17  libdispatch.dylib               0x192d3db90 _dispatch_source_invoke + 500
18  libdispatch.dylib               0x192d430f4 _dispatch_root_queue_drain + 104
19  libdispatch.dylib               0x192d434fc _dispatch_worker_thread2 + 76
20  libsystem_pthread.dylib         0x192ed16bc _pthread_wqthread + 356
21  libsystem_pthread.dylib         0x192ed154c start_wqthread + 4

ekeventstore を初期化するコードは次のとおりです。

+ (EKEventStore *) sharedStore {
     static EKEventStore *sharedEventStore;

    if (sharedEventStore == nil) {
        sharedEventStore = [[EKEventStore alloc] init];
        [sharedEventStore requestAccessToEntityType: EKEntityTypeEvent completion:^(BOOL granted, NSError *error) {
        }];
        [sharedEventStore reset];
    }

    return sharedEventStore;
}

イベントを取得するコード:

NSPredicate *predicate = [[CalendarHelper sharedStore] predicateForEventsWithStartDate:startDate
                                                        endDate:endDate
                                                      calendars:[[showableCalendars copy] autorelease]];
NSArray *result = [[CalendarHelper sharedStore] eventsMatchingPredicate:predicate];

イベントを更新/作成するには:

EKEvent *event = [[CalendarHelper sharedStore] eventWithIdentifier:eventId];
if(event != nil) {
    event.title = title;
    event.startDate = startDate;
    event.endDate = endDate;
    NSLog(@"Updating...");
    NSLog(@"+++ %@", event.eventIdentifier);

    [[CalendarHelper sharedStore] saveEvent:event span:EKSpanThisEvent commit:commit error:nil];
    NSLog(@"Updated.");
}
else {
    NSLog(@"No event, no update");
}

どんな手掛かり?

4

1 に答える 1