从设置启用或禁用日历后应用程序崩溃

时间:2013-11-05 07:40:54

标签: ios iphone ekeventstore

我已经在我的应用程序中实现了EKEventStore,EKCalendar,以便在应用程序中创建EKEvent。它工作正常,除非我没有更改设置的权限。但是当我从设置中更改了请求的访问权限(开/关或关/开)时,应用程序崩溃了。我无法找到错误。如果有人有想法那么请帮助我。这是我实施的代码:

 self.eventStore = [[EKEventStore alloc] init];
 [self checkEventStoreAccessForCalendar];

 -(void)checkEventStoreAccessForCalendar
{
EKAuthorizationStatus status = [EKEventStore authorizationStatusForEntityType:EKEntityTypeEvent];
switch (status)
{
   case EKAuthorizationStatusAuthorized: [self accessGrantedForCalendar];
        break;
    case EKAuthorizationStatusNotDetermined: [self requestCalendarAccess];
        break;
    case EKAuthorizationStatusDenied:
    case EKAuthorizationStatusRestricted:
    {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Privacy Warning" message:@"Permission was not granted for Calendar"
                                                       delegate:nil
                                              cancelButtonTitle:@"OK"
                                              otherButtonTitles:nil];
        [alert show];
    }
        break;
        default:
        break;
} }

  -(void)requestCalendarAccess
 {
   [self.eventStore requestAccessToEntityType:EKEntityTypeEvent completion:^(BOOL granted,  
NSError *error)
 {
     if (granted)
     {
         dispatch_async(dispatch_get_main_queue(), ^{
        });
     }
 }];
}

 -(void)accessGrantedForCalendar
{
self.defaultCalendar = self.eventStore.defaultCalendarForNewEvents;
EKEvent *addEvent = [EKEvent eventWithEventStore:self.eventStore];
addEvent.title = [NSString stringWithFormat:@"%@", textcontainer.text];
}

#pragma mark EKEventEditViewDelegate

-(void)eventEditViewController:(EKEventEditViewController *)controller
      didCompleteWithAction:(EKEventEditViewAction)action{
[self dismissViewControllerAnimated:YES completion:^
 {
     if (action != EKEventEditViewActionCanceled)
     {
         dispatch_async(dispatch_get_main_queue(), ^{
          });
     }
 }];
 }

- (EKCalendar *)eventEditViewControllerDefaultCalendarForNewEvents:(EKEventEditViewController *)controller
{
return self.defaultCalendar;
 }

1 个答案:

答案 0 :(得分:0)

当你的应用程序进入后台时,它应该保存所有状态,并准备好被杀死。当有人关闭对日历的访问权限时,系统处理该问题的最简单方法就是杀死你的应用程序,这就是它发生的原因。如果您通过点击“返回应用程序”切换回应用程序'最重要的是,你可以注意到你的应用程序将从头开始,而不是从你离开的地方开始。尝试不使用断点,您会注意到更改。

  • 所以它实际上不是崩溃。