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

雨燕双飞 提交于 2020-01-19 17:18:25

问题


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!


回答1:


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;
}



回答2:


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.




回答3:


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
}


来源:https://stackoverflow.com/questions/42091850/how-to-get-the-voip-call-log-information-in-application-call-kit

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