-->

blocking phone numbers in call kit has couple of e

2019-08-21 09:33发布

问题:

I'm trying to add a blocking phone number feature to my app and I had some error and my problem got solved in This question that I asked. the person who solved my problem there, also guided me that I have to use group application to share my core data( I store the phone numbers here ) with the Call Directory.

the code below is in the main app(blocking viewController)

@IBAction func BtnAddA(_ sender: Any) {
    if !(EntPhonenumber.text?.isEmpty)!
    {
        let blackedPhonenumbers_CoreData = BlockedPhoneNumbers(context: PersistanceService.context)
        blackedPhonenumbers_CoreData.phoneNumber = Int64.init(EntPhonenumber.text!)!
        PersistanceService.saveContext()
        getCoreData()
        TableView.reloadData()


        CXCallDirectoryManager.sharedInstance.reloadExtension(withIdentifier: "MY CALL DIRECTORY BUNDLE ID") { (err) in
            if let error = err
            {
                print("we got some error")
                print("@\(error)")

                print("==\(error.localizedDescription)")
            }
            else
            {
                print("good to go")
            }
        }
    }
}

And I have Used this linkto share my core data with my call directory.

And the code below shows the call directory handler:

      class CallDirectoryHandler: CXCallDirectoryProvider {

        var listPhoneNumbers:[CXCallDirectoryPhoneNumber] = []
        let context = CoreDataStorage.mainQueueContext()

        func fetchData() {
            self.context.performAndWait{ () -> Void in

                let FetchedData = NSManagedObject.findAllForEntity("BlockedPhoneNumbers", context: self.context)

                if (FetchedData != nil) {
    //                self.fetchData = (FetchedData?.last as! BlockedPhoneNumbers)
                    listPhoneNumbers = FetchedData as! [CXCallDirectoryPhoneNumber]
                }
                else {

                }

            }
        }
override func beginRequest(with context: CXCallDirectoryExtensionContext) {
        context.delegate = self
        // Check whether this is an "incremental" data request. If so, only provide the set of phone number blocking
        // and identification entries which have been added or removed since the last time this extension's data was loaded.
        // But the extension must still be prepared to provide the full set of data at any time, so add all blocking
        // and identification phone numbers if the request is not incremental.
        if context.isIncremental {
            addOrRemoveIncrementalBlockingPhoneNumbers(to: context)
            fetchData()

            addOrRemoveIncrementalIdentificationPhoneNumbers(to: context)
        } else {
            addAllBlockingPhoneNumbers(to: context)
            fetchData()

            addAllIdentificationPhoneNumbers(to: context)
        }



        context.completeRequest()
    }

    private func addAllBlockingPhoneNumbers(to context: CXCallDirectoryExtensionContext) {
        // Retrieve all phone numbers to block from data store. For optimal performance and memory usage when there are many phone numbers,
        // consider only loading a subset of numbers at a given time and using autorelease pool(s) to release objects allocated during each batch of numbers which are loaded.


        let blockedPhoneNumbers: [CXCallDirectoryPhoneNumber] = listPhoneNumbers//[ phone Numbers here with country code! ]
        for phoneNumber in blockedPhoneNumbers.sorted(by: <) {
            context.addBlockingEntry(withNextSequentialPhoneNumber: phoneNumber)
        }

        context.completeRequest()
    }
}

Whenever I press the button in blocking VC, I get an error which says:

@Error Domain=com.apple.CallKit.error.calldirectorymanager Code=0 "(null)" ==The operation couldn’t be completed. (com.apple.CallKit.error.calldirectorymanager error 0.)

and sometimes :

@Error Domain=NSCocoaErrorDomain Code=4097 "connection to service named ARWD.whoIsThis.Call-Directory.apple-extension-service" UserInfo={NSDebugDescription=connection to service named ARWD.whoIsThis.Call-Directory.apple-extension-service} ==Couldn’t communicate with a helper application.

does anybody knows what am I doing wrong and what is the solution??