ios: fix resetting CallKit's CXProvider

When CallKit is enabled / disabled, a new CXProvider must be created in order to
not confuse CallKit (it misbehaves otherwise).
This commit is contained in:
Saúl Ibarra Corretgé 2019-04-17 17:13:26 +02:00 committed by Saúl Ibarra Corretgé
parent eb38300c0d
commit 9a92dc578c
1 changed files with 7 additions and 3 deletions

View File

@ -27,7 +27,7 @@ import Foundation
// MARK: - CallKit proxy
private static let provider: CXProvider = {
private static var provider: CXProvider = {
let configuration = CXProviderConfiguration(localizedName: "")
return CXProvider(configuration: configuration)
}()
@ -52,9 +52,13 @@ import Foundation
/// Defaults to enabled, set to false when you don't want to use CallKit.
@objc public static var enabled: Bool = true {
didSet {
if enabled == false {
provider.setDelegate(nil, queue: nil)
provider.invalidate()
if enabled {
guard isProviderConfigured() else { return; }
provider = CXProvider(configuration: providerConfiguration!)
provider.setDelegate(emitter, queue: nil)
} else {
provider.setDelegate(nil, queue: nil)
}
}
}