Первая регистрация для VOIP-уведомлений в
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
requestPushKit()
return true
}
Импорт набора вызовов
import CallKit
Регистрация Push-набора
fileprivate func requestPushKit() {
let voipRegistry = PKPushRegistry(queue: DispatchQueue.main)
voipRegistry.delegate = self
voipRegistry.desiredPushTypes = [.voIP]
}
Делегаты VOIP (Push Kit)
extension AppDelegate: PKPushRegistryDelegate {
func pushRegistry( registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
if type == PKPushType.voIP {
let tokenParts = pushCredentials.token.map { data -> String in
return String(format: "%02.2hhx", data)
}
let tokenString = tokenParts.joined()
print(tokenString)
}
}
func pushRegistry( registry: PKPushRegistry, didInvalidatePushTokenFor type: PKPushType) {
}
func pushRegistry( registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type:PKPushType, completion: @escaping () -> Void) {
if type == PKPushType.voIP {
self.incomingCall()
}
}
func pushRegistry( registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) {
if type == PKPushType.voIP {
self.incomingCall()
}
}
}
Вызов метода входящего вызова
fileprivate func defaultConfig() -> CXProviderConfiguration{
let config = CXProviderConfiguration(localizedName: "My App")
config.includesCallsInRecents = true
config.supportsVideo = true
config.maximumCallGroups = 5
config.maximumCallsPerCallGroup = 10
// config.iconTemplateImageData = UIImagePNGRepresentation(UIImage(named: "pizza")!)
// config.ringtoneSound = "ringtone.caf"
return config
}
func incomingCall(){
let provider = CXProvider(configuration: defaultConfig())
provider.setDelegate(self, queue: nil)
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .generic, value: "Pete Za")
update.hasVideo = true
provider.reportNewIncomingCall(with: UUID(), update: update, completion: { error in })
}
И методы делегата набора вызова
extension AppDelegate : CXProviderDelegate {
func providerDidReset( provider: CXProvider) {
}
func providerDidBegin( provider: CXProvider) {
}
func provider( provider: CXProvider, perform action: CXAnswerCallAction) {
action.fulfill()
}
func provider( provider: CXProvider, perform action: CXEndCallAction) {
action.fulfill()
}
func provider( provider: CXProvider, perform action: CXStartCallAction) {
}
func provider( provider: CXProvider, perform action: CXSetHeldCallAction) {
}
func provider( provider: CXProvider, timedOutPerforming action: CXAction) {
}
func provider( provider: CXProvider, perform action: CXPlayDTMFCallAction) {
}
func provider( provider: CXProvider, perform action: CXSetGroupCallAction) {
}
func provider( provider: CXProvider, perform action: CXSetMutedCallAction) {
}
// func provider(_ provider: CXProvider, execute transaction: CXTransaction) -> Bool {
//
// }
}
Тем не менее, если вам что-то требуется, сообщите нам об этом.:)