2017-06-20 16 views
0

通知カレンダーまたはイベントカレンダーのいずれかがポップアップを最初に表示し、複数のカレンダーを作成し、イベント/リマインダーを保存しないという問題が発生しています。私はplistに設定されたプロパティを持っています。Xamarin iOS EventStore.Getcalendars returns 0

  var calendarEvent = await ANApi.FetchCalendarInfoAsync(AppCore.CurrentAppInfo.AppId); 
      calendarEvent.Count(); 

      foreach (var calEvent in calendarEvent.ToList()) 
      { 
       if (calEvent.Type == 1) 
       { 
        AppEvent.Current.EventStore.RequestAccess(EKEntityType.Event, (bool granted, NSError err) => 
         { 
          if (granted) 
          { 
           lock (_lock) 
           { 
            CreateCalendar(EKEntityType.Event); 
            CreateEvent(calEvent); 
           } 
          } 

         }); 
       } 
       else 
       { 
        AppEvent.Current.EventStore.RequestAccess(EKEntityType.Reminder, (bool remGranted, NSError remErr) => 
        { 
         if (remGranted) 
         { 
          lock (_lock) 
          { 
           CreateCalendar(EKEntityType.Reminder); 
           CreateReminder(calEvent); 
          } 
         } 
        }); 
       } 
      } 

私は唯一のイベントやリマインダーを受け付けております場合は、コードが正常に動作しますが、私はイベントやリマインダーの両方を受けておりますので、それが失敗している。以下は、私はイベントやリマインダーのためのアクセスを要求するために使用していたコードです私のカレンダーを正しく作成してください。

これは私がカレンダーを作成しています方法です:

public void CreateCalendar(EKEntityType type) 
    { 
     bool calExists = false; 
     var appName = NSBundle.MainBundle.ObjectForInfoDictionary("CFBundleDisplayName"); 

     //This returns 0 calendars, depending on which event's request was displayed first. 
     EKCalendar[] calendars = AppEvent.Current.EventStore.GetCalendars(type); 
     foreach (EKCalendar cal in calendars) 
     { 
      if (type == EKEntityType.Event) 
      { 
       if (PersistentLayer.Instance.GetString(Constant.CALENDAR_ID) == null) 
        calExists = false; 
       else if (cal.CalendarIdentifier == PersistentLayer.Instance.GetString(Constant.CALENDAR_ID)) 
        calExists = true; 
      } 
      else 
      { 
       if (PersistentLayer.Instance.GetString(Constant.REMINDER_CALENDAR_ID) == null) 
        calExists = false; 
       else if (cal.CalendarIdentifier == PersistentLayer.Instance.GetString(Constant.REMINDER_CALENDAR_ID)) 
        calExists = true; 
      } 
     } 
     //Create a Calendar based on the App's name. If name cannot be found use App Calendar 
     if (!calExists) 
     { 
      EKCalendar calendar = EKCalendar.Create(type, AppEvent.Current.EventStore); 

      if (appName != null) 
       calendar.Title = appName.ToString(); 
      else 
       calendar.Title = "App"; 
      EKSource localSource = null; 

      foreach (EKSource source in AppEvent.Current.EventStore.Sources) 
      { 
       if (source.SourceType == EKSourceType.CalDav) 
       { 
        localSource = source; 
        break; 
       } 
      } 

      if (localSource == null) 
       return; 

      calendar.Source = localSource; 
      calendar.CGColor = new CGColor(255, 255, 0); 
      NSError calError; 

      AppEvent.Current.EventStore.SaveCalendar(calendar, true, out calError); 
      if (calError != null) 
      { 
       this.SimpleAlert("Error saving Calender", calError.ToString(), "OK", null); 
       return; 
      } 

      //Store the calendar Id so we can use it when saving events 
      if (type == EKEntityType.Event) 
       PersistentLayer.Instance.Edit().PutString(Constant.CALENDAR_ID, calendar.CalendarIdentifier); 
      else 
       PersistentLayer.Instance.Edit().PutString(Constant.REMINDER_CALENDAR_ID, calendar.CalendarIdentifier); 
     } 
    } 

は、私が起こって競合状態のいくつかの並べ替えがあることを信じて、私はそれを把握することができていません。私は試してそれを働かせるために複数のことを試みましたが、私は成功しませんでした。

ありがとうございました

答えて

0

私はそれを理解して終了しました。最初に、私はコードを壊し、イベントの後に受信したすべてのリマインダを作成しました。

最初は、イベントを作成しようとするとエラードメイン= EKCADErrorDomainコード= 1010が返されました。私がこれを解決したのは、イベントストアをリセットすることでした。私がこれをしたら、リマインダーとイベントの両方に対して、カレンダーが正しく作成され、イベントとリマインダーがそれぞれのカレンダーに追加されました。