ios - 功能执行延迟(请求访问权限后)IOS

标签 ios swift3 ekeventstore

我需要获得使用 iOS 提醒的权限,为此我正在这样做:

switch EKEventStore.authorizationStatus(for: .reminder) {
case .authorized:                    
    print("Access granted")
    //everything's normal here
    //executing my function here

case .denied:
    print("Access denied")
case .notDetermined:       
    print("not defined yet")

    //No determined so asking for permission
    self.eventStore.requestAccess(to: .reminder) { (granted, error) -> Void in
        if granted == true {
            print("permission granted")

           //executing my function here after getting permissions but this piece of code executes after a long delay 
           //this piece of codes are executing after a while say 5-10 seconds

        }else if error != nil{       
            print("ther's an error : \(error)")
        }            
    }

default:
    print("Case Default")
}   

如上所述,当应用程序提示用户获得提醒权限并且用户授予权限时,我的下一个功能得到执行但过了一段时间(5-10 秒)

谁能解释为什么会这样?

最佳答案

requestAccess 的完成不会在主线程上被调用。将 permissions granted 代码放入 Dispatch Async 中:

DispatchQueue.main.async {
  print("permission granted")
}

关于ios - 功能执行延迟(请求访问权限后)IOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41167357/

相关文章:

ios - 发送尝试失败后出现错误的 Twitter 结果

android - Android 中的 NSURLCache 替代方案

ios - 向 UITextField、UILabel、UIView 自定义类添加自定义功能

swift - 更改了哪个日历(使用 EKEventStoreChangedNotification?)

ios - .calendarsForEntityType(EKEntityType.Reminder) 不返回提醒列表列表

ios - 在向日历 Xcode 添加事件时处理世界时间(使用 T)

ios - 多个推送 Segues 到 Storyboard 中的一个 View Controller

ios - 使用 UITableViewAutomaticDimension 时 UITableView 在 begin/endUpdates 后跳起来

iOS Swift 存储对 Realm 的 Alamofire 响应

swift - Swift 字典中的可选 AnyObject 值