当提交的号码从提交到阻止的文本时,
呼叫目录扩展名无效。
我试过下面的代码。
@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()
}
任何有用的建议......
答案 0 :(得分:0)
在上面的代码中,我看不到您的分机号码CXCallDirectoryExtensionContext.addBlockingEntry(withNextSequentialPhoneNumber:)
。您必须在扩展程序的beginRequest(with:)
方法中调用此方法,以告知系统阻止电话号码。