我一直在开发一个应用程序,在一个组织中存储所有联系人的详细信息。主要目标是我的应用程序应该能够检测到呼入或呼出的电话,并且应该显示出号码所属的人是谁。例如,此应用程序将作为Truecaller应用程序工作。
我试过用谷歌搜索,发现在IOS中不可能检测到来电号码。
我在ios中阅读了CallKit,并了解了Call目录扩展。虽然我不清楚如何实现它&我不知道这件事是否能解决我的问题。
如果IOS设备接到来自未知号码的呼叫,系统是否会选择我的应用程序并搜索未知号码的联系人,并在呼叫者屏幕上显示相关信息?或者还有其他方法吗?

最佳答案

经过几个不眠之夜,我找到了解决问题的办法。
在Xcode中,转到文件->新建->目标
ios - 识别iOS中未知的GSM调用-LMLPHP
选择Call Directory Extension并单击Next
ios - 识别iOS中未知的GSM调用-LMLPHP
不管名字是什么,点击finish
ios - 识别iOS中未知的GSM调用-LMLPHP
现在你的应用程序应该类似于
ios - 识别iOS中未知的GSM调用-LMLPHP
转到CallDirectoryExtension.swift并将代码替换为

import Foundation
import CallKit
class CallDirectoryHandler: CXCallDirectoryProvider {
override func beginRequest(with context: CXCallDirectoryExtensionContext) {
    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
    }

    for phoneNumber in phoneNumbersToBlock {
        context.addBlockingEntry(withNextSequentialPhoneNumber: CXCallDirectoryPhoneNumber(phoneNumber)!)
    }

    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
    }

    for (phoneNumber, label) in zip(phoneNumbersToIdentify, phoneNumberIdentificationLabels) {
        context.addIdentificationEntry(withNextSequentialPhoneNumber: CXCallDirectoryPhoneNumber(phoneNumber)!, label: label)
    }

    context.completeRequest { (suc) in
        print(suc)
    }
}

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

private func retrievePhoneNumbersToIdentifyAndLabels() -> (phoneNumbers: [String], labels: [String])? {
    // retrieve list of phone numbers to identify, and their labels
    return (["+94123456789", "+94234567891"],
            ["John Doe","Angelina Jollie",])
}

}

现在运行并启动应用程序。然后转到设置->电话->呼叫阻塞和识别,然后打开权限。
注意:如果您在CallDirectoryHandler中对联系人列表进行了任何更改,首先必须关闭权限,然后从设备中删除应用程序。
每次调试应用程序时,每次更新列表时,都要重做这些步骤。

关于ios - 识别iOS中未知的GSM调用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47399024/

10-14 21:24
查看更多