我需要获得使用 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/