In my SIP app, I integrated Linphone to it. I can do outgoing calls and receive incoming calls successfully when app is open, but but as a new feature, I want to be able to receive this call when the application is closed. I researched some documentations and I found out Callkit and Pushkit might work for this aim. But I dont know when someone calls me how can I trigger this incoming call in background. I followed the github issue below, but it didn't help.
https://github.com/BelledonneCommunications/linphone-iphone/issues/612
You can look how did I integrate Pushkit and Callkit to my codes.
import UIKit
import CallKit
import PushKit
class SplashScreen : UIViewController, CXProviderDelegate, PKPushRegistryDelegate {
@IBOutlet weak var logoHeightConstraint: NSLayoutConstraint!
@IBOutlet weak var logoWidthConstraint: NSLayoutConstraint!
@IBOutlet weak var launcherIcon: UIImageView!
private var registeredToBackgroundEvents = false
let TAG = "SplashScreen"
/// register to back from backround event
private func registerToBackFromBackground() {
if(!registeredToBackgroundEvents) {
NotificationCenter.default.addObserver(self,
selector: #selector(viewDidBecomeActive),
name: UIApplication.didBecomeActiveNotification, object: nil)
registeredToBackgroundEvents = true
}
}
/// unregister from back from backround event
private func unregisterFromBackFromBackground() {
if(registeredToBackgroundEvents) {
NotificationCenter.default.removeObserver(self,
name: UIApplication.didBecomeActiveNotification, object: nil)
registeredToBackgroundEvents = false
}
}
@objc func viewDidBecomeActive(){
MyApp.showLoadingDialog = true
MyApp.writeLog("SPI_SplashScreen|","viewDidBecomeActive() removeObserver")
unregisterFromBackFromBackground()
MyApp.writeLog("SPI_SplashScreen|","viewDidBecomeActive()->jumpToWelcomeScreen()")
jumpToWelcomeScreen()
}
override func viewDidLoad() {
super.viewDidLoad()
MyApp.currentUIViewController = self
let registry = PKPushRegistry(queue: nil)
registry.delegate = self
registry.desiredPushTypes = [PKPushType.voIP]
}
override func viewDidAppear(_ animated: Bool) {
self.navigationController?.isNavigationBarHidden = true
MyApp.currentUIViewController = self
}
override func viewWillDisappear(_ animated: Bool) {
unregisterFromBackFromBackground()
}
func providerDidReset(_ provider: CXProvider) {
MyApp.writeLog(TAG, "providerDidReset")
}
func provider(_ provider: CXProvider, perform action: CXAnswerCallAction) {
action.fulfill()
MyApp.writeLog(TAG, "answer call action")
}
func provider(_ provider: CXProvider, perform action: CXEndCallAction) {
action.fulfill()
MyApp.writeLog(TAG, "end call action")
}
func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, for type: PKPushType) {
MyApp.writeLog(TAG, "push registry didUpdate")
MyApp.writeLog(TAG, pushCredentials.token.map { String(format: "%02.2hhx", $0) }.joined())
print(pushCredentials.token.map { String(format: "%02.2hhx", $0) }.joined())
}
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType, completion: @escaping () -> Void) {
MyApp.writeLog(TAG, "push registry didReceiveIncomingPushWith")
let config = CXProviderConfiguration(localizedName: "My App")
config.includesCallsInRecents = false
config.supportsVideo = true
let provider = CXProvider(configuration: config)
provider.setDelegate(self, queue: nil)
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .generic, value: "Someone")
update.hasVideo = true
provider.reportNewIncomingCall(with: UUID(), update: update, completion: { error in })
}
}
Actually, when I write these codes in command line (terminal), test notifications come to me.
curl -v -d '{"aps":{"alert":"hello"}}' --http2 --cert YeniCallKit.pem:202148 https://api.development.push.apple.com/3/device/177e7861396ad0256886673d1efb3c82d5adb54e86dc5cfd781356c1672cfa07
I want to receive background calls that when app is closed or iphone is locked. So anyone can help me on this issue?