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

后端 未结 3 802
失恋的感觉
失恋的感觉 2020-12-12 02:41

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

相关标签:
3条回答
  • 2020-12-12 03:00

    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;
    }
    
    0 讨论(0)
  • 2020-12-12 03:05

    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
    }
    
    0 讨论(0)
  • 2020-12-12 03:13

    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.

    0 讨论(0)
提交回复
热议问题