2017-02-22 3 views
0

イベントを設定できるiPhoneアプリケーションがあります。イベントの日付は選択できますが、時間は選択できません。これを行うために、iCalendarに接続しました。現在、イベントページにいるときは、iCalendarアイコンを押すだけで、カレンダーの同じ日付に自動的にiCalendarが開きます。イベントの名前を入力するには、時間を選択する必要があります。だから私たちは、イベントの名前を複製しています(2回貼ります)。私たちのアプリには1つ、Icalendarにはもう1つあります。iOSからiCalendarにパラメータを渡す方法Swift

iCalendarがIcalendarボタンを押したときに起こるように、iCalendarを動かすことはできますか?それは、指定された日付のカレンダーを開き、時間を選択すると...イベントも配置されていますか?

イベント情報を2回入力する必要がないように、これを設定する最良の方法は何でしょうか。私に知らせてくれてありがとう、ありがとう。

+1

EventKitは、あなたのアプリを離れることなく、Appleのカレンダーでイベントを作成させます。 –

+0

@DavidShawありがとうございますが、Eventkitは追加されたイベントの後に変更を許可しません –

答えて

0

まず第一には次のようにEventKitUIインポートする必要があります。

輸入EventKitUI

とデリゲートを追加します。EKEventEditViewDelegate

として渡されたデータを使用して新しいイベント画面を開くには、次のコードを追加します。

let eventStore = EKEventStore() 
    eventStore.requestAccess(to: .event, completion: {(_ granted: Bool, _ error: Error?) -> Void in 
     if granted { 
      let event = EKEvent(eventStore: eventStore) 
      event.title = "My Event Test 1" 
      //event.location = location; 
      event.startDate = Date() 
      event.endDate = event.startDate.addingTimeInterval(60 * 30) 
      //event.notes  = notes; 
      let controller = EKEventEditViewController() 
      controller.eventStore = eventStore 
      controller.event = event 
      controller.editViewDelegate = self 
      self.present(controller, animated: true, completion: { _ in }) 
     } 
    }) 

ユーザーの操作に応じて応答を処理します。

func eventEditViewController(_ controller: EKEventEditViewController, didCompleteWith action: EKEventEditViewAction) { 
switch (action) { 
case .canceled: 
    // User tapped "cancel" 
    break; 
case .saved: 
    // User tapped "save" 
    break; 
case .deleted: 
    // User tapped "delete" 
    break; 
} 
self.dismiss(animated: true, completion: nil) 
}