How can an app determine if its being launched from a terminated state due to Voip Push?

[NOTE: This question is about VoiP pushes, not about ordinary pushes] [NOTE2: The question is NOT about how to set up an app to receive Voip Pushes, read it properly what it is actually asking].

If the app is terminated and a Voip push arrives then within didFinishLaunchingWithOptions the options a nil. (This can be contrasted against if an app is launched when the user taps on a local notification for example).

How does an app know its being launched due to the arrival of a VoIP push, as opposed to a push arriving while the app is already in the background?


You need to set a delegate to the PKPushRegistry object you have created and specify it as a VOIP type:

let voipRegistry = PKPushRegistry(queue: nil) voipRegistry.delegate = myPushDelegate voipRegistry.desiredPushTypes = [PKPushType.voIP]

Your delegate will have to conform to the PKPushRegistryDelegate protocol.

Then, implement the pushRegistry(_:didReceiveIncomingPushWith:for:completion:) protocol function (reference) - this function will be called upon receiving a push (even if at the app was terminated earlier).

the function description:

Notifies the delegate that a remote push has been received.

the specified push type. Call the completion handler as soon as you have finished processing the payload.This method is invoked when a push notification has been received for

please note thet the function: pushRegistry(_:didReceiveIncomingPushWith:for:) has been deprecated so don't be confused with the one I mentioned above.

More information about the PKPushRegistryDelegate protocol: here

About the actual question, there is a work around for that - the idea is to create create a flag that will be destroyed when app will terminate but as soon as it wakes up it status will change - if the app woke up from background the flag status will be saved but if the app woke up after it was terminated the flag will hold the default value.

In the push's delegate class:

import PushKit class PushDelegate: PKPushRegistryDelegate { var flag = false func pushRegistry(_ registry: PKPushRegistry, didReceiveIncomingPushWith payload: PKPushPayload, forType type: PKPushType) { if flag { print("the app woke up from background") } else { print("the app was terminated") flag = true } } }

In addition, in order to detect if the user launched the app (this is the only case that the app will be in active state) use the code below:

let state = UIApplication.shared.applicationState if state == .background { // background } else if state == .active { // foreground }


  • Register for voip notifications outside of app delegate
  • Is possible use silent push to wake up APP and get the VOIP call?
  • Can we restart an app programmatically in ios when the phone is turned on [closed]
  • how to use mjsip with j2me
  • ios 8 periodic background process even after app termination
  • Method didInvalidatePushTokenForType is not calling on token expired using Twilio
  • How to get google-services.json from Developer console?
  • Removing event listeners on automatically created multiple elements
  • Error “Reflect.defineMetadata” while trying to load a transient web worker
  • Run EF6 Query in separate Thread on WinForm Button Click Event
  • Connect Node.js with Oracle on Windows platform
  • How to add javascript in a prestashop module
  • Rails 5 - Google Maps - Javascript error - initMap is not a function - fixing one js issue creates a
  • Accessing another variable in the same class with a click event
  • C Program Compiled with Cygwin and Called from Python Hangs
  • Granting permissions to Azure Active Directory Web Application automatically
  • Spring Integration Bridge with poller not working as expected for JMS
  • How to move an element within a structure, possibly with zippers?
  • Google analytics measurement protocol session timeout and query time limits
  • Javascript/Jquery runs fast in desktop browsers, but slow in mobile/smartphone browsers…should I spl
  • PushKit for VOIP iOS apps
  • Open Existing DB in MySQL WorkBench
  • What does “t” refer to in this SQL?
  • Getting the scrolling offset when storing coordinates
  • How to make Twilio api Post request with the help of AFNetworking?
  • Primefaces ManyCheckbox inside ui:repeat calls setter method only for last loop
  • Autofac with Web API 2 - Parameter-less constructor error
  • Android changing fragment order inside FragmentPagerAdapter
  • how does System.Web.HttpRequest::PathInfo work?
  • Not able to aggregate on nested fields in elasticsearch
  • Menu Color Fade on Hover with Jquery
  • Incrementing object id automatically JS constructor (static method and variable)
  • How to format a variable of double type
  • VB.net deserialize, JSON Conversion from type 'Dictionary(Of String,Object)' to type '
  • How can I get HTML syntax highlighting in my editor for CakePHP?
  • Free memory of cv::Mat loaded using FileStorage API
  • How do I configure my settings file to work with unit tests?
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • unknown Exception android
  • Binding checkboxes to object values in AngularJs