iOS callkit-来电记录历史记录



我在应用程序接近或在后台时仅用于接收到的呼叫(按下通知通知),我才在我们的应用程序中实现了呼叫套件。我只是注意到,每次我收到呼叫并使用CallKit显示它时,此呼叫会自动出现在"呼叫"历史记录(本机呼叫应用程序中的Recents Tab)中。

每当我单击最近的一个时,我的应用程序是简历或启动。用户按最近的通话后,我想让该应用程序将其放置在传出电话,但我没有找到任何内容。

  • 是否有一种方法可以检测到该应用程序是从此调用中打开/恢复的?
  • 我们可以禁用此CallKit功能吗?

感谢您提供信息:)

我想让该应用在用户按下之后放置一个呼叫 最近的电话,但我什么都没找到。

在您的应用程序的Info.plist中,您必须在NSUserActivityTypes密钥中具有INStartAudioCallIntent和/或INStartVideoCallIntent,并且您的应用程序委托必须实现-application:continueUserActivity:restorationHandler:方法来处理开始呼叫的意图。有关详细信息,请参见SpeakerBox示例应用程序。

我们可以禁用此CallKit功能吗?

如果您不为呼叫的CXCallUpdate设置remoteHandle,则Recents中的项目将无法按下。

用于将来参考;

  1. 呼叫套件提供商配置应具有此通用和电话号码类型的列表

    config.supportedHandleTypes = [.generic,.phoneNumber]
    
  2. CallKit Update remoteHandle应该像以下

    那样初始化
     update.remoteHandle = CXHandle(type: .generic, value:String(describing: payload.dictionaryPayload["caller_id"]!))
    

3.您应该通过选择项目'target'构建阶段>链接二进制文件与库,然后单击 按钮

  1. 您应该在您的信息中添加instartcallintent。

    <key> NSUserActivityTypes </key>
         <array>
             <string>INStartCallIntent</string>
         </array>
    

  2. 对于Swift 5,您应该将以下功能添加到SceneDelegate.swift

    func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {}
    

或对于Swift 4及以下,您应该将以下功能添加到AppDelegate.swift

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {
 return true
}

然后将下面的代码添加到您的继续用户攻击函数

let interaction = userActivity.interaction
            if let startAudioCallIntent = interaction?.intent as? INStartAudioCallIntent{
        
                let contact = startAudioCallIntent.contacts?.first
            
                let contactHandle = contact?.personHandle
    
                    if let phoneNumber = contactHandle?.value {
                       print(phoneNumber)
                      // Your Call Logic
                        }
                    }
         
            }
  

您应该警告

 INStartAudioCallIntent' was deprecated in iOS 13.0: INStartAudioCallIntent is deprecated. Please adopt INStartCallIntent instead

应用此建议失败了,因为Startaudiocallintent不能被施放到插入插入式上,所以请忽略它。

非常重要的在场景委托中继续使用UserActivity函数被称为WHAN应用程序已终止,因此在启动应用程序时运行意图,您应该将代码块添加到

 func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {}

,您的代码应该像以下

 func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
     
        let contentView = ContentView()
        // Use a UIHostingController as window root view controller.
        if let windowScene = scene as? UIWindowScene {
            let window = UIWindow(windowScene: windowScene)
            window.rootViewController = UIHostingController(rootView: contentView.environmentObject(AppDelegate.shared)) // This is my code so you may not use Appadelegate.shared. ignore it
            self.window = window
            window.makeKeyAndVisible()
        }
        
        
        if let userActivity = connectionOptions.userActivities.first {
            let interaction = userActivity.interaction
            if let startAudioCallIntent = interaction?.intent as? INStartAudioCallIntent{
        
                let contact = startAudioCallIntent.contacts?.first
            
                let contactHandle = contact?.personHandle
                    if let phoneNumber = contactHandle?.value {
                        
                        // Your Call Logic
                    }
         
            }
          }
        
    }

最新更新