#If OBJC
//
// CXCallDirectoryProvider.h
// CallKit
//
// Copyright © 2016 Apple. All rights reserved.
//
@available (iOS 10.0, *)
public class CXCallDirectoryProvider: NSObject, NSExtensionRequestHandling {
public func beginRequest (with context: CXCallDirectoryExtensionContext )
}}
//
// CXCallDirectoryExtensionContext.h
// CallKit
//
// Copyright © 2016 Apple. All rights reserved.
// //
@available (iOS 10.0, *)
public class CXCallDirectoryExtensionContext: NSExtensionContext {
public func addBlockingEntry (withNextSequentialPhoneNumber phoneNumber: String )
public func addIdentificationEntry (withNextSequentialPhoneNumber phoneNumber: String , label: String)
public func completeRequest (completionHandler completion: ( (Bool) -> Swift Void) = nil.?)
}}
import Foundation
import CallKit
class CallDirectoryHandler: CXCallDirectoryProvider {
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 {
Context.addBlockingEntry (withNextSequentialPhoneNumber: phoneNumber)
}}
// --- 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) {
Context.addIdentificationEntry (withNextSequentialPhoneNumber: phoneNumber, label: label)
}}
// --- 5
Context.completeRequest ()
}}
private func retrievePhoneNumbersToBlock () -> [ String] {?
// retrieve list of phone numbers to block
return [ "+ 8618xxxx157"]
}}
private func retrievePhoneNumbersToIdentifyAndLabels () -> ( phoneNumbers: [String], labels: [String]) {?
// retrieve list of phone numbers to identify, and their labels
return ([ "+ 8618xxxx569"] , [ " Test"])
}}
}}
#End if