0

call directory extension is not working when provided number from the text filed to block.

I tried with below code.

@IBAction func blockButtonAction(sender: UIButton) {
        if(numberTxfield.text == nil) {
            NSLog("Number should not be empty")
        }
        let callDicProvider = CallDirectoryHandler()
        callDicProvider.retrievePhoneNumbersToBlock(numberIs: numberTxfield.text!)
    }

// addBlockingPhoneNumbers is method for blocking the phone numbers.

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

Any suggestions helpful...

Stuart M
  • 11,458
  • 6
  • 45
  • 59
Ashok Narvaneni
  • 196
  • 1
  • 2
  • 8
  • 1
    You are fundamentally misunderstanding how extensions work. They are their own process and instantiated/managed by the OS. You can't create an instance of them directly in apps. Be sure to read Apple's App Extension Programming Guide to better understand this and use the XCode new project wizard to generate an extension shell as a proper starting point. – Matt Weinecke Sep 23 '16 at 11:33

1 Answers1

0

In the code above I do not see your extension calling CXCallDirectoryExtensionContext.addBlockingEntry(withNextSequentialPhoneNumber:). You must call this method from within the extension's beginRequest(with:) method in order to tell the system to block the phone numbers.

Stuart M
  • 11,458
  • 6
  • 45
  • 59