0

I'm working on an app, once the app goes to background(when the user taps the home button in iPhone) and receives and answers the phone call I have to perform some action.

Below is the code I tried,

callCenter = CTCallCenter()

        self.callCenter!.callEventHandler = {(call: CTCall) -> Void in
            if (call.callState == CTCallStateConnected)
            {
               //do something
            }

            else if (call.callState == CTCallStateDisconnected)
            {
               //do something
            }
        }
    }

-- The event gets called when the app is foreground and receives the phone call, but doesn't work when the app is in the background.

Any solution to make it work?

Note: I'm submitting the app to the app store(iOS 9 and above, swift 2.3), so turning VoIP feature ON will not work for me as it might lead to rejection.

Paulw11
  • 108,386
  • 14
  • 159
  • 186
Master Stroke
  • 5,108
  • 2
  • 26
  • 57

1 Answers1

-2

You can put your code in one of these methods in your AppDelegate.swift:

func applicationWillResignActive(_ application: UIApplication) {
    // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
    // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
    // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
    // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}
Alexandre Lara
  • 2,464
  • 1
  • 28
  • 35