【问题标题】:App crashed after enable or disable calendar from settings从设置中启用或禁用日历后应用程序崩溃
【发布时间】:2013-11-05 07:40:54
【问题描述】:

我在我的应用程序中实现了 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;
 }

【问题讨论】:

  • 设置断点并说出你在哪一行发生了崩溃
  • @LombaX 我已经为所有方法设置了断点。但在崩溃之前它没有去任何方法。
  • 我可能错了,但是一旦更改设置,您的应用程序不会重新启动吗?我已经通过几个应用程序注意到了这一点。您的应用可能实际上并没有崩溃,而是“强制关闭”,我可能又错了。
  • @sbarow 它打开了。但没有用..
  • @MinkleGarg 假设您已正确设置断点,这意味着崩溃发生在这两种方法之前。如果在- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 的第一行设置断点会发生什么?

标签: ios iphone ekeventstore


【解决方案1】:

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

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-09-02
    • 1970-01-01
    • 2020-05-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多