I am still struggling with this issue across many programs. I have a closure that I need a value back from but as it is with async, it's not waiting for the value and therefore the calling method is erroring because it has the wrong bool.
Here is an example:
func requestNotificationAuthorization() -> Bool {
var retVal: Bool = false
let authOptions = UNAuthorizationOptions.init(arrayLiteral: .alert, .badge, .sound)
self.userNotificationCenter.requestAuthorization(options: authOptions) { (success, error) in
if let error = error {
retVal = false
print(error.localizedDescription)
} else {
retVal = true
}
}
return retVal
}
I need to know if the user has in fact authorized notifications but during the initial call, it will always return false or true if I set the value to an initial true. Now, it will come back with a value at some point but the code that reads it has already been processed.
There has to be a way to do this that I just haven't found yet. I am not looking for a workaround but an actual solution. Any help in pointing me in the correct direction would be greatly appreciated.