首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用呼叫目录分机识别主叫方ID

使用呼叫目录分机识别主叫方ID
EN

Stack Overflow用户
提问于 2019-12-31 16:04:41
回答 1查看 473关注 0票数 0

我已经在我的应用程序中实现了Call Directory Extension来识别被叫id。但无法在收到来电时查看我的应用程序名称或呼叫者详细信息。无法调试呼叫目录分机,被苹果公司以安全为由起诉。已经包含了我的代码在下面。

代码语言:javascript
运行
复制
override func beginRequest (with context: CXCallDirectoryExtensionContext) {
// --- 1
guard let phoneNumbersToBlock = retrievePhoneNumbersToBlock () else {
NSLog ( "Unable to retrieve phone numbers to block" )
let error = NSError (domain: "CallDirectoryHandler" , code: 1 , userInfo: nil )
context.cancelRequest (withError: error)
return
}

// --- 2
for phoneNumber in phoneNumbersToBlock {
    let phoneNumberr : CXCallDirectoryPhoneNumber = CXCallDirectoryPhoneNumber(phoneNumber)!
context.addBlockingEntry (withNextSequentialPhoneNumber: phoneNumberr)
}

// --- 3
guard let (phoneNumbersToIdentify, phoneNumberIdentificationLabels) = retrievePhoneNumbersToIdentifyAndLabels () else {
NSLog ( "Unable to retrieve phone numbers to identify and their labels" )
let error = NSError (domain: "CallDirectoryHandler" , code: 2 , userInfo: nil )
context.cancelRequest (withError: error)
return
}

// --- 4
for (phoneNumber, label) in zip (phoneNumbersToIdentify, phoneNumberIdentificationLabels) {
    let phoneNumberrr : CXCallDirectoryPhoneNumber = CXCallDirectoryPhoneNumber(phoneNumber)!
context.addIdentificationEntry (withNextSequentialPhoneNumber: phoneNumberrr, label: label)
}

// --- 5
context.completeRequest ()
}

private func retrievePhoneNumbersToBlock () -> [ String ]? {
 // retrieve list of phone numbers to block
 return [ "+ 919488775260" ]
 }

 private func retrievePhoneNumbersToIdentifyAndLabels () -> (phoneNumbers: [ String ], labels: [ String ])? {
 // retrieve list of phone numbers to identify, and their labels
 return ([ "+ 919385338505" ], [ "test" ])
 }

如果启用了任何配置,我可能会遗漏。请帮帮我。

EN

回答 1

Stack Overflow用户

发布于 2020-01-02 15:59:42

我找到了解决方案。由于Apple的安全原因,基本上不可能调试呼叫目录分机。但是你可以通过app中的reload函数进行测试。请找到下面的代码。

代码语言:javascript
运行
复制
CXCallDirectoryManager.sharedInstance.reloadExtension(withIdentifier: "com.harman.CallerIDTestApp.CallerExtension", completionHandler: { (result: Error?)->Void in
        guard let errorChk = result else { return }
        print(errorChk)
        let errorCode = (errorChk as NSError).code
        switch errorCode {
        case CXErrorCodeCallDirectoryManagerError.Code.unknown.rawValue:
            print("Extension could not be load for an unknown reason.")
        case CXErrorCodeCallDirectoryManagerError.Code.noExtensionFound.rawValue:
            print("Could not load extension.  Extension not found")
        case CXErrorCodeCallDirectoryManagerError.Code.loadingInterrupted.rawValue:
            print("Could not load extension.  Extension was interrupted while loading")
        case CXErrorCodeCallDirectoryManagerError.Code.entriesOutOfOrder.rawValue:
            print("Could not load extension.  Call entries are out of order")
        case CXErrorCodeCallDirectoryManagerError.Code.duplicateEntries.rawValue:
            print("Could not load extension.  Duplicate entries")
        case CXErrorCodeCallDirectoryManagerError.Code.maximumEntriesExceeded.rawValue:
            print("Could not load extension.  Maximum entries exceeded")
        case CXErrorCodeCallDirectoryManagerError.Code.extensionDisabled.rawValue:
            print("Extension not enabled in Settings")
        case CXErrorCodeCallDirectoryManagerError.Code.unexpectedIncrementalRemoval.rawValue:
            print("Unexpected incremental removal")
        case CXErrorCodeCallDirectoryManagerError.Code.currentlyLoading.rawValue:
            print("Could not load extension.  The extension is currently loading")
        default:
            print("Could not load extension.")
        }
    })

在app委托中使用上面的代码来测试您的呼叫目录分机是否正常工作。

在"CallDirectoryHandler“中,beginRequest方法应该如下所示。

代码语言:javascript
运行
复制
override func beginRequest(with context: CXCallDirectoryExtensionContext) {
    context.delegate = self
    if context.isIncremental {
        addOrRemoveIncrementalBlockingPhoneNumbers(to: context)

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

        addAllIdentificationPhoneNumbers(to: context)
    }

    context.completeRequest()
}

请检查context是否为isIncremental,否则代码将无法工作。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59541326

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档