3

I've implemented CallKit in our app. Calls our app makes are displayed in the native phone app's recents list.

When tapping an entry for our app in the recents list, our app is started. Is there a way to find out which number(/entry) was used to start our app? (openURL or something)

  • 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:16

1 Answers1

10

You'll want to implement application(application: UIApplication, continueUserActivity userActivity: NSUserActivity, restorationHandler: ([AnyObject]?) -> Void) -> Bool on the AppDelegate. For this particular action, userActivity will have a interaction property, with an intent property that is an instance of INStartAudioCallIntent (or INStartVideoCallIntent if your app does video).

The intent object has an array of INPerson contact objects on it, which can be used to determine information about what was dialed.

If your app doesn't load any contacts into the system, your calls are one-to-one (as opposed to group) and you just want access to the "dialed number", you'll probably find what you want at intent.contacts?.first?.personHandle?.value.

Also note that you'll need to link and import the Intents framework.

Update

The previous answer was only half-right. There are two ways of getting this information, and both should be implemented.

The continueUserActivity variant above will be called when an item in recents is tapped (or a contact is selected), and your app is already running.

However, if your app is not currently running, then it will be launched and continueUserActivity will not be called. Instead, the system will invoke your AppDelegate's didFinishLaunchingWithOptions with a UIApplicationLaunchOptionsKey.userActivityDictionary, which can be used like:

if let activityOptions = launchOptions?[UIApplicationLaunchOptionsKey.userActivityDictionary] as? [String: AnyObject],
   let activity = activityOptions["UIApplicationLaunchOptionsUserActivityKey"] as? NSUserActivity {
  self.launchWithActivity(activity)
}

Once you have the NSUserActivity instance, the behavior is the same as it is in continueUserActivity

Update Again

Per @vivek takrani in the comments below, it appears that continueUserActivity may be called at all times, whether the app was previously open or not. I would test this on earlier versions of iOS 10 if you intend to support it, as I don't believe this was the case at the time this answer was written.

Colin M
  • 13,010
  • 3
  • 38
  • 58
  • Thanks, this is what I needed! – Rasmus Höglund Oct 04 '16 at 12:43
  • @RasmusHöglund & Colin, when tap on the recents list, my app is not starting and not showing call option in recents. I don't know what I missed? – RJV Kumar Nov 07 '16 at 12:32
  • It only opens for entries that your app created (by using callkit). Do you have entries that your app created in recents? – Rasmus Höglund Nov 08 '16 at 14:49
  • @RJVKumar Also, in order to get your app to show up in the contacts list, and other parts of the system, you must set `supportedHandleTypes` on your `CXProviderConfiguration` to include the types of handles your app supports. This will enable the option to call using your app directly from the contacts. – Colin M Nov 08 '16 at 15:49
  • Hey, the continueUserActivity method is called all the times, even when the user clicked on a call from call logs & app was closed. – vivek takrani Sep 06 '18 at 11:54
  • This may be the case in more recent iOS updates. It always seemed strange that it worked this way before. I'll update my answer to reference your comment. – Colin M Sep 07 '18 at 12:47
  • Is it compulsory to add Deep Linking functionality to get selected VOIP app number and start audio calling in that app? – Parth Barot Oct 02 '19 at 09:37