我是Swift的新手。我的CallDirectoryHandler文档就是这样。我尝试了多种方式,例如使用国家/地区代码和不使用国家/地区代码。但这并不会阻止下面的数字。我没有为ViewController.swift写任何有关数字阻塞的代码。有什么帮助吗?我哪里错了?谢谢。
import Foundation
import CallKit
class CallDirectoryHandler: CXCallDirectoryProvider {
override func beginRequest(with context: CXCallDirectoryExtensionContext) {
context.delegate = self
do {
try addAllBlockingPhoneNumbers(to: context)
} catch {
NSLog("Unable to add blocking phone numbers")
let error = NSError(domain: "CallDirectoryHandler", code: 1, userInfo: nil)
context.cancelRequest(withError: error)
return
}
context.completeRequest()
}
private func addAllBlockingPhoneNumbers(to context: CXCallDirectoryExtensionContext) throws {
let allPhoneNumbers: [CXCallDirectoryPhoneNumber] = [ 058858904 ]
for phoneNumber in allPhoneNumbers {
context.addBlockingEntry(withNextSequentialPhoneNumber: phoneNumber)
}
context.addBlockingEntry(withNextSequentialPhoneNumber: +9058858904)
context.addBlockingEntry(withNextSequentialPhoneNumber: 9058858904)
let phoneNumber : CXCallDirectoryPhoneNumber = CXCallDirectoryPhoneNumber("+9058858904")!
context.addBlockingEntry(withNextSequentialPhoneNumber: phoneNumber)
let phoneNumber2 : CXCallDirectoryPhoneNumber = CXCallDirectoryPhoneNumber("9058858904")!
context.addBlockingEntry(withNextSequentialPhoneNumber: phoneNumber2)
let phoneNumber3 : CXCallDirectoryPhoneNumber = CXCallDirectoryPhoneNumber("058858904")!
context.addBlockingEntry(withNextSequentialPhoneNumber: phoneNumber3)
}
}