0

当从文本字段中提供号码以阻止时,呼叫目录扩展不起作用。

我尝试使用以下代码。

@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()
    }

任何有用的建议...

4

1 回答 1

0

在上面的代码中,我没有看到您的分机调用CXCallDirectoryExtensionContext.addBlockingEntry(withNextSequentialPhoneNumber:)。您必须从分机的beginRequest(with:)方法中调用此方法,以便告诉系统阻止电话号码。

于 2016-09-22T18:16:01.887 回答