Detecting GSM Call States in IOS 10 (Swift 3, Xcode 8) and Notification from Background state

前端 未结 5 835
长发绾君心
长发绾君心 2021-02-05 19:15

TLDR: Detect call end event from background Please see update to the question below:

Is it possible to detect/get an event for call state in IOS 10 usin

5条回答
  •  情话喂你
    2021-02-05 19:56

    "Is it possible to detect/get an event for call state in IOS 10 using Swift from background state"

    Yes.

    The background state of your application is only a temporary pit-stop on it's way to becoming suspended. When this occurs the system will stop all processes that your code is trying to react to.

    Apple does this for a very good reason. They do not applications the user is not using to eat up battery on the device. If they didn't do this your iPhone battery would become depleted very quickly. So to enforce this, all applications that remain in the background state will eventually be suspended. That is, of course, unless you configure your app in a couple of different ways.

    1) Background Executions

    This it looks like you may already be doing in your application. But this would allow your application to execute any long running tasks that may not have completed or that need to be extended for a little bit. As you have figured out there is a limit to how long these background tasks are allowed to run. It will not execute while your application is suspended. It will keep your application in the background state for up to 3 minutes to complete it's work. Once this has finished your application will immediately enter suspended state.

    2) Background Modes

    The most reliable way to ensue your application will remain in the background state is to enable a capability in your projects configuration that will indicate your application utilizes a valid background mode. My app Sublam does this. It is a music player application that enhances the music in your iTunes to sound it's best. It would be very annoying to the user if they could only listen to music while the application was in the foreground. Almost kept prisoner, never able to leave or the music would stop. I enabled a background mode to keep my application in the background and away from the dreaded suspended state. This way my application can handle user input to change the song, pause, play or any other action my application would need react to.

    Your application will need to conform to a valid background mode to ensure that it remains in the background state and to be able to react to any calls coming in. Otherwise, the CXCallObserverDelegate methods won't execute at all.


    "I need to get the state of normal CDMA/GSM calls, not VOIP based calls"

    As Mukund and Raza said above - you can not use CallKit to determine that information. Hopefully this will become a new feature of CallKit in the future. But as of now this functionality is not supported.

提交回复
热议问题