如何在应用程序中获取voip通话记录信息 - Call Kit

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

我在我的 voip 应用程序中实现了通话工具包,我在其中生成了来电或去电的通话记录(在 phone 最近选项卡上可见)。 当我点击通话记录时,它会打开我的应用程序。我已经重写了 UIApplication 委托方法来获取处理程序。

- (BOOL)application:(UIApplication *)application
continueUserActivity:(NSUserActivity *)userActivity
 restorationHandler:(void (^)(NSArray *restorableObjects))restorationHandler  

但是我无法在 NSUserActivity 中获取与通话记录相关的信息。 我如何在我的应用程序中获取通话记录信息?

非常感谢任何帮助。谢谢!

我们可以从 userActivity,

中获取 phone number
- (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;
}

在 Swift 4

中完成解决方案

您需要配置您的应用以继续调用 userActivity。

  • 在 CXProviderConfiguration

    中添加 supportedHandleTypes属性
        let configuration = CXProviderConfiguration.init(localizedName:"Product name")
        configuration.supportedHandleTypes = Set([CXHandle.HandleType.generic])
    
  • 在项目 Info.plist 中添加 INStartAudioCallIntent 类型的 NSUserActivityTypes

  • 目标项目 -> 构建阶段 -> 库添加 Intents.framework

  • 在您的 AppDelegate 中导入 Intents 框架
  • 下面是从 userActivity

    中提取 phone 号码的代码
    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
    }
    

    希望对您有所帮助。

调用信息封装在INPerson对象中,可以从INInteraction对象中解析出来。

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.

您必须从 NSActivity 对象中获取交互和意图对象。

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
}