[英]saveEvent returning “No calendar has been set”
我試圖從我的應用程序中將事件保存到日歷中。 我的代碼適用於iOS 7,但在iOS 6上 ,它返回沒有設置日歷。
在iOS 7上,應用程序提示用戶授予對日歷的訪問權限。但是,iOS 6沒有出現此類提示。雖然應用程序在“ 設置” - >“隱私” - >“日歷”中被授予訪問權限。
是的,我已經實現了requestAccessToEntityType:completion:
.
這是我的代碼片段 。
EKEventStore *objStore = [[EKEventStore alloc]init];
if ([objStore respondsToSelector:@selector(requestAccessToEntityType:completion:)])
{
// iOS 6 and later
[objStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted, NSError *error)
{
dispatch_async(dispatch_get_main_queue(), ^{
if (granted)
{
// code here for when the user allows your app to access the calendar
EKEvent *calEvent = [EKEvent eventWithEventStore:objStore];
calEvent.title = mstrTitleEvent;
calEvent.startDate = self.dateToBeSet;
calEvent.endDate = self.dateToBeSet;
calEvent.calendar = objStore.defaultCalendarForNewEvents;
EKAlarm *objAlarm = [EKAlarm alarmWithAbsoluteDate:self.dateToBeSet];
[calEvent addAlarm:objAlarm];
NSError *error;
BOOL _bStatus = [objStore saveEvent:calEvent span:EKSpanThisEvent commit:YES error:&error];
UIAlertView *alertV;
if(_bStatus)
{
alertV = [[UIAlertView alloc]initWithTitle:@"Congratulations" message:@"Saved To Calendar" delegate:nil cancelButtonTitle:@"Right On!" otherButtonTitles:nil];
[alertV show];
}
else
{
alertV = [[UIAlertView alloc]initWithTitle:@"Alert" message:[NSString stringWithFormat:@"Error saving to calendar, with error %@.",[error localizedDescription]] delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
[alertV show];
}
}
else
{
// code here for when the user does NOT allow your app to access the calendar
UIAlertView *alertV = [[UIAlertView alloc]initWithTitle:@"Alert" message:@"Please grant access to the calendar, and try again later." delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
[alertV show];
}
});
}];
}
只是設法以某種方式找到我的問題的解決方案。 我不得不從一個頁面導航到另一個頁面,所以將鏈接發布到兩個頁面。
首先 - > https://discussions.apple.com/message/16497282#16497282
然后,從那里到 - > https://discussions.apple.com/message/16479587#16479587
我不得不進入設置> iCloud>並啟用日歷 。 之后,我嘗試嘗試並運行我的代碼,它再次正常運行。
如果你遇到類似的問題,請嘗試這樣做。
我在iPad 2上工作,並在設備上安裝了iOS 6.1.3。
令人驚訝我在兩個不同的設備上測試我的代碼,一個工作正常,另一個不能工作。 只是查看設置,其中一個沒有工作有iCloud日歷和提醒關閉,只需打開它們現在一切正常...這必須是一個bug
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.