I have implemented call kit in my voip app in which i generate the call logs for incoming or outgoing calls (visible on phone recent tab). When i click on call logs it will
We can take phone number from userActivity,
- (BOOL)application:(UIApplication *)application continueUserActivity:(NSUserActivity *)userActivity restora`tionHandler:(void(^)(NSArray * __nullable restorableObjects))restorationHandler{
INInteraction *interaction = userActivity.interaction;
INStartAudioCallIntent *startAudioCallIntent = (INStartAudioCallIntent *)interaction.intent;
INPerson *contact = startAudioCallIntent.contacts[0];
INPersonHandle *personHandle = contact.personHandle;
NSString *phoneNumber = personHandle.value;
}
Call information is encapsulated in the INPerson object, which can be parsed from INInteraction objects.
When providing contacts to SiriKit, any INInteraction objects delivered to other apps includes the information contained in INPerson objects. Do not include any information that you are not willing to share with other apps.
You have to get the interaction and intent object from the NSActivity object.
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
if let intent = activity.interaction?.intent as? INStartCallIntent,
let contacts = intent.contacts,
let value = contacts.first?.personHandle?.value {
let contactHandle name = value
// This is the contact handle, now you can add your business logic.
}
return true
}
Complete solution in Swift 4
You need to configure your app to get continue userActivity called.
Add supportedHandleTypes property in CXProviderConfiguration
let configuration = CXProviderConfiguration.init(localizedName:"Product name")
configuration.supportedHandleTypes = Set([CXHandle.HandleType.generic])
Add NSUserActivityTypes of type INStartAudioCallIntent in Info.plist of your project
Target Project -> Build Phase -> Libraries add Intents.framework
Below is the code to extract phone number from userActivity
func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
let intraction = userActivity.interaction
let startAudioCallIntent = intraction?.intent as? INStartAudioCallIntent
let contact = startAudioCallIntent?.contacts?[0]
let contactHandle = contact?.personHandle
if let phoneNumber = contactHandle?.value {
print(phoneNumber)
}
return true
}
Hope this helps You.