当从文本字段中提供号码以阻止时,呼叫目录扩展不起作用。
我尝试使用以下代码。
@IBAction func blockButtonAction(sender: UIButton) {
if(numberTxfield.text == nil) {
NSLog("Number should not be empty")
}
let callDicProvider = CallDirectoryHandler()
callDicProvider.retrievePhoneNumbersToBlock(numberIs: numberTxfield.text!)
}
// addBlockingPhoneNumbers 是阻止电话号码的方法。
func retrievePhoneNumbersToBlock(numberIs: String) -> Void {
let numberFromString = Int64(numberIs)
print("phone number is \(numberIs) and numberFromString \(numberFromString)")
let number: CXCallDirectoryPhoneNumber = numberFromString!
blockArray.append(number)
print("blockArray number is \(blockArray) and \(blockArray.count) and \(number)")
do {
try addBlockingPhoneNumbers(to: contextIs)
} catch {
NSLog("Unable to add blocking phone numbers")
let error = NSError(domain: "CallDirectoryHandler", code: 1, userInfo: nil)
contextIs.cancelRequest(withError: error)
return
}
CXCallDirectoryManager.sharedInstance.reloadExtension(withIdentifier: "com.something.something.CallIDExtension", completionHandler: {(error) -> Void in
if let error = error {
print(error.localizedDescription)
}
})
contextIs.completeRequest()
}
任何有用的建议...