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 - UITableViewCell 选择背景颜色更改不起作用

iphone - 存储大笔记内容-objective-c

ios - UniversalLink 不适用于 iOS 14 设备,但在模拟器上运行良好

ios - 如何以编程方式更改我的 viewController 的 View ?

ios - EKEventStore 请求访问不起作用

ios - 快速旋转手势x和y离轴问题

ios - 为什么对成员 'Subscript' 的引用不明确?

java - 我正在实例化从 Java (J2ObjC) 转译的 Swift 非 ARC Objective-C 类,它是否泄漏安全?

ios - defaultCalendarForNewEvents 被定义为可选的,但是不能使用可选绑定(bind)来检查它是否为 nil

ios - 从日历中检索带有标识符的事件时应用程序崩溃