Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

EKEventStore requestAccessToEntityType crashing app in iOS 10 and above

I have app in which I have to add events in default calendar which worked fine until iOS 10. Now in iOS 10 it is not granting access. I have set use legacy swift language version to yes. My code is

let eventStore = EKEventStore()
switch EKEventStore.authorizationStatusForEntityType(EKEntityType.Event) {
   case .Authorized:
            //access
   case .Denied:
            print("Access denied")
   case .NotDetermined:
       eventStore.requestAccessToEntityType(EKEntityType.Event, completion:
                {[weak self] (granted: Bool, error: NSError?) -> Void in
                    if granted {
                        //access
                    } else {
                        print("Access denied")
                    }
                })
   default:
            print("Case Default")
  }

While debug my app is crashing at eventStore.requestAccessToEntityType in Xcode 8.

Screenshot of debug

My app is live and I need to solve it. Any help is appropriated. Thanks in advance.

like image 669
Max Avatar asked Jan 06 '23 06:01

Max


1 Answers

On iOS 10 builds, you need to set a description message for the permission alert on Info.plist

Important: An iOS app linked on or after iOS 10.0 must include in its Info.plist file the usage description keys for the types of data it needs to access or it will crash. To access Reminders and Calendar data specifically, it must include NSRemindersUsageDescription and NSCalendarsUsageDescription, respectively.

from Apple Docs

like image 127
Leonardo Avatar answered Jan 13 '23 08:01

Leonardo