3

I've implemented call kit in our app only for received incoming call when the app is close or on background (push call notification). I just noticed that every time I received a call and use callkit to display it, this call automatically appear in the call history (Recents tab in native Call App).

Every time I click on one of those recent, my App is resume or launch. I wanted to make the app place an outgoing call after the user press the recent call but I didn't find anything about it.

  • Is there a way to detect that the app was opened / resumed from this call recent click ?
  • Can we disable this callkit feature ?

Thanks for providing information :)

  • You can get the solution in Swift 4 [Here](https://stackoverflow.com/a/57375678/2393843). Hope this helps you. – Shubham Aug 06 '19 at 12:36

2 Answers2

3

I wanted to make the app place an outgoing call after the user press the recent call but I didn't find anything about it.

In your app's Info.plist, you must have INStartAudioCallIntent and/or INStartVideoCallIntent in the NSUserActivityTypes key, and your app delegate must implement the -application:continueUserActivity:restorationHandler: method to handle the start call intent. See the Speakerbox example app for details.

Can we disable this callkit feature ?

If you don't set a remoteHandle for the call's CXCallUpdate, the item in Recents won't be pressable.

user102008
  • 30,736
  • 10
  • 83
  • 104
  • Can I open my app on answering the call from system UI? – Choxx Jan 19 '17 at 07:44
  • I was able to call through my app clicking in an entry in the native call log. But this is not working anymore. Do you know if something has changed on iOS 11? The NSUserActivityTypes did not make any difference to me. – Gabriel Gava Nov 06 '17 at 16:52
  • @GabrielGava Do you have an update to it? NSUserActivityTypes on info.plist does not seem to fix the issue. – Legolas Mar 06 '19 at 18:54
  • @Legolas see here, this fixed it for me: https://stackoverflow.com/questions/46051359/application-continueuseractivity-restorationhandler-not-called-in-ios-11/46077628#46077628 – Henry Mar 17 '19 at 21:09
1

for future reference;

  1. call kit provider configuration should have this list of generic and phone number types

    config.supportedHandleTypes = [.generic,.phoneNumber]
    
  2. Callkit update remotehandle should be initialized like below

     update.remoteHandle = CXHandle(type: .generic, value:String(describing: payload.dictionaryPayload["caller_id"]!))
    

3.You should add Intents.framework to your project by selecting project>target>Build Phases> Link Binary With Libraries and click + button

  1. You should add INStartCallIntent to your info.plist like below

    <key> NSUserActivityTypes </key>
         <array>
             <string>INStartCallIntent</string>
         </array>
    
  2. for swift 5 you should add below function to your SceneDelegate.swift

    func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {}
    

or for swift 4 and below you should add below function to Appdelegate.swift

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {

 return true
}

then add code below to your continue useractivity function

let interaction = userActivity.interaction
            if let startAudioCallIntent = interaction?.intent as? INStartAudioCallIntent{
        
                let contact = startAudioCallIntent.contacts?.first
            
                let contactHandle = contact?.personHandle
    
                    if let phoneNumber = contactHandle?.value {
                       print(phoneNumber)
                      // Your Call Logic
                        }
                    }
         
            }

  

you should get a warning that

 INStartAudioCallIntent' was deprecated in iOS 13.0: INStartAudioCallIntent is deprecated. Please adopt INStartCallIntent instead

applying this suggestion fails because startAudioCallIntent cant be cast to INStartCallIntent so ignore it.

VERY IMPORTANT continue useractivity function in scene delegate is not called whan app is terminated so to run your intent when app is start you should add code block to

 func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {}

and your code should be like below

 func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
     
        let contentView = ContentView()

        // Use a UIHostingController as window root view controller.
        if let windowScene = scene as? UIWindowScene {
            let window = UIWindow(windowScene: windowScene)
            window.rootViewController = UIHostingController(rootView: contentView.environmentObject(AppDelegate.shared)) // This is my code so you may not use Appadelegate.shared. ignore it
            self.window = window
            window.makeKeyAndVisible()
        }
        
        
        if let userActivity = connectionOptions.userActivities.first {
            let interaction = userActivity.interaction
            if let startAudioCallIntent = interaction?.intent as? INStartAudioCallIntent{
        
                let contact = startAudioCallIntent.contacts?.first
            
                let contactHandle = contact?.personHandle

                    if let phoneNumber = contactHandle?.value {
                        
                        // Your Call Logic
                    }
         
            }
          }
        
    }
Bilal Şimşek
  • 5,453
  • 2
  • 19
  • 33
  • How can I write call logic for xcode 13 and swiftui lifecycle where is no more Scene and App Delegate? – Patrik Spišák Oct 14 '21 at 12:18
  • Can you explain more what do you want to do? – Bilal Şimşek Oct 15 '21 at 08:07
  • I have already figgure out. For SwiftUI has to bee all logic inside this code: `.onContinueUserActivity(NSStringFromClass(INStartCallIntent.self), perform: { userActivity in` But have no ide how can I assign number from recent calls to user profile and by tapping on that number open my app and start calling – Patrik Spišák Oct 15 '21 at 08:23