How to get the voip call log information in application - Call Kit

吃可爱长大的小学妹 提交于 2019-11-29 15:49:35

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.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!