如何将日历从iPhone导入我的应用程序,以便我可以处理数据?
我正在使用C#Montouch / Xamarin.iOS。
答案 0 :(得分: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 );
答案 1 :(得分: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