Swift playground - 地址簿 - 访问被拒绝

时间:2014-08-18 18:19:56

标签: swift abaddressbook swift-playground

是否可以测试一些与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
}

它打印我拒绝访问权限-.-

0 个答案:

没有答案