是否可以在 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
}
它打印我访问被拒绝-.-