All, I created the following function:
func determineStatus() -> Bool {
let status = ABAddressBookGetAuthorizationStatus()
var ok = false
switch status {
case .NotDetermined:
println("Asking for Grant")
ABAddressBookRequestAccessWithCompletion(nil) {
(granted:Bool, err:CFError!) in
ok = granted
println("Granted Status: \(granted)")
}
case .Authorized:
println("Authorized")
ok = true
case .Restricted:
println("Restricted")
ok = false
case .Denied:
println("Denied")
ok = false
}
if ok == true {
println("Creating AB Instance")
return self.createAddressBook()
} else {
self.adbk = nil
println("Not Authorized")
return false
}
}
And I call it from within my Master - Detail View. The first time I call it the view appears before the alert window asking for authorization, and it's empty. I get in my console:
Asking for Grant Not Authorized And, after I authorize: Granted Status: true So the if ok == true part of determineStatus get executed before the ABAddressBookRequestAccessWithCompletion(nil) completes. The second time I run it I get the data displayed. How can I change determineStatus in order for the if ok == true statement to be executed after ABAddressBookRequestAccessWithCompletion(nil) finishes?