是否可以测试一些与swifts playground中的地址簿api相关的代码?我不知道如何让xcode访问我的地址簿。
这是我的代码:
let authorizationStatus = ABAddressBookGetAuthorizationStatus()
if (authorizationStatus == ABAuthorizationStatus.NotDetermined) {
println("requesting access...")
var emptyDictionary: CFDictionaryRef?
var addressBook = !ABAddressBookCreateWithOptions(emptyDictionary, nil)
ABAddressBookRequestAccessWithCompletion(addressBook,{success, error in
if success {
// do something
}
else {
println("unable to request access")
}
})
}
else if (authorizationStatus == ABAuthorizationStatus.Denied || authorizationStatus == ABAuthorizationStatus.Restricted) {
println("access denied")
}
else if (authorizationStatus == ABAuthorizationStatus.Authorized) {
println("access granted")
// do something else
}
它打印我拒绝访问权限-.-