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 open my app. I've overridden the UIApplication
delegate method to get the handler.
- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler
But i unable to get call log related information in NSUserActivity
.
How i can get the call log information in my app?
Any help much appreciate. Thanks!
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;
}
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
- Import Intents framework in your AppDelegate
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.
来源:https://stackoverflow.com/questions/42091850/how-to-get-the-voip-call-log-information-in-application-call-kit