2014-01-30 40 views

回答

1

使用EventKit

首先,你有權要求日曆訪問:

EKEventStore EventStore = new EKEventStore(); 
EventStore.RequestAccess (EKEntityType.Event, 
     (bool granted, NSError e) => { 
       if (granted) 
         //do something here 
       else 
         new UIAlertView ("Access Denied", 
"User Denied Access to Calendar Data", null, 
"ok", null).Show(); 
       }); 

要查詢的時間範圍內的所有事件,做這樣的事情:

DateTime startDate = DateTime.Now.AddDays (-7); 
DateTime endDate = DateTime.Now; 
// the third parameter is calendars we want to look in, to use all calendars, we pass null 
NSPredicate query = App.Current.EventStore.PredicateForEvents (startDate, endDate, null); 

// execute the query 
EKCalendarItem[] events = App.Current.EventStore.EventsMatching (query); 
+0

真棒的感謝! – Goober

0

你也可以使用Xamarin.Mobile。這將是跨平臺的。

例如,從api docs

var abook = new AddressBook(); 
abook.RequestPermissions().ContinueWith (t => 
{ 
    if (!t.Result) 
     return; // Permission denied 

    var builder = new StringBuilder(); 

    // Full LINQ support 
    foreach (Contact c in abook.Where (c => c.FirstName == "Eric" && c.Phones.Any())) 
    { 
     builder.AppendLine (c.DisplayName); 
     foreach (Phone p in c.Phones) 
      builder.AppendLine (String.Format ("{0}: {1}", p.Label, p.Number)); 

     builder.AppendLine(); 
    } 

    contacts.Text = builder.ToString(); // Update UI 

}, TaskScheduler.FromCurrentSynchronizationContext()); // Ensure we're on the UI Thread