2016-05-09 4 views
0

EventKit内にカレンダーイベントを作成できるようにするための現在の方法があります。Swift iOSで定期的に開催されるWeeklyイベントEventKit

func createEvent(eventStore: EKEventStore, title: String, startDate: NSDate, endDate: NSDate) { 
    let event = EKEvent(eventStore: eventStore) 

    event.title = title 
    event.startDate = startDate 
    event.endDate = endDate 
    event.calendar = eventStore.defaultCalendarForNewEvents 

    do { 
     try eventStore.saveEvent(event, span: .ThisEvent) 
     savedEventId = event.eventIdentifier 
    } catch { 
     print("Bad things happened") 
    } 
} 

ただし、定期的な予定を作成するために、ユーザーが数日を選択できるようにしたいと考えています。たとえば、ユーザは午前10時5分の時刻を設定し、月曜日、水曜日、木曜日を選択します。このイベントがユーザーカレンダーで正しくスケジュールされるように、私はどのようにEventKitを作成できますか?

答えて

2

あなたの投稿のタイムスタンプは5月に戻っているので、もう助けが必要ないかもしれませんが、この質問に遭遇した他の人は、EKRecurrenceRule classを利用して行事。

はここに(あなたのシナリオのような)毎週金曜日のイベントのスケジュールを設定するためにそれを使用してのObjective-Cの例です:

// The EKRecurrenceRule accepts an NSArray of day objects, I did this to make adding multiple days easier 
NSMutableArray *daysArr = [[NSMutableArray alloc] init]; 

// Days of the week are ordered Sunday to Saturday, 1-7 
EKRecurrenceDayOfWeek *theDay = [[EKRecurrenceDayOfWeek alloc] initWithDayOfTheWeek:6 weekNumber:0]; 

// Add Friday to the array 
[daysArr addObject:theDay]; 

// Instantiate the EKRecurrenceRule, giving it a weekly frequency and the day of the week 
EKRecurrenceRule *recurrenceRule = [[EKRecurrenceRule alloc] initRecurrenceWithFrequency:EKRecurrenceFrequencyWeekly interval:1 daysOfTheWeek:daysArr daysOfTheMonth:nil monthsOfTheYear:nil weeksOfTheYear:nil daysOfTheYear:nil setPositions:nil end:nil]; 

// Apply it to the event 
[event setRecurrenceRules:@[recurrenceRule]]; 

私はこれが誰かを役に立てば幸い!

関連する問題