I am trying to open ViewController
on received push notification. I am doing it like this
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, for type: PKPushType) {
guard let aps = payload.dictionaryPayload[AnyHashable("aps")] as? NSDictionary else {
return
}
startCustomCallController(apnData: app)
}
func startCustomCallController(apnData: NSDictionary) {
let storyBord = UIStoryboard(name: "PrivateUi", bundle: nil)
guard let controller = storyBord.instantiateViewController(withIdentifier: "NewIncomingCallViewController") as? NewIncomingCallViewController else{
print("Error instantiating view controller")
return
}
controller.apnData = apnData
guard let appdelegate = UIApplication.shared.delegate as? AppDelegate else {
print("appdelegate is missing")
return
}
UIView.transition(with: appdelegate.window!, duration: 0.5, options: .transitionCrossDissolve, animations: {
appdelegate.window!.rootViewController = controller
}, completion: nil)
}
It is working when app is open (In Foreground) But not working when is in background or killed. Is it not possible or do I need to make some changes?
It is not possible to start ViewController
from background model I think. If you want to open viewcontroller
for call related task batter to use callkit
func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, forType type: PKPushType) {
// report new incoming call
}```