【问题标题】:iOS Callkit - incoming Call Recents HistoryiOS Callkit - 来电最近历史记录
【发布时间】:2017-05-04 21:31:46
【问题描述】:

我在我们的应用程序中实现了呼叫套件,仅用于在应用程序关闭或后台(推送呼叫通知)时收到的来电。我只是注意到,每次我接到一个电话并使用 callkit 显示它时,这个电话都会自动出现在通话记录中(本机通话应用中的“最近”选项卡)。

每次我点击最近的一个,我的应用程序就会恢复或启动。 我想在用户按下最近通话后让应用拨出电话,但我没有找到任何相关信息。

  • 有没有一种方法可以检测到应用程序已从此通话最近点击中打开/恢复?
  • 我们可以禁用这个 callkit 功能吗?

感谢您提供信息:)

【问题讨论】:

  • 您可以在 Swift 4 Here 中获得解决方案。希望这对您有所帮助。

标签: ios call callkit nativeapplication


【解决方案1】:

供日后参考;

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

    config.supportedHandleTypes = [.generic,.phoneNumber]
    
  2. Callkit 更新远程句柄应该像下面这样初始化

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

3.您应该将 Intents.framework 添加到您的项目中,方法是选择 project>target>Build Phases> Link Binary With Libraries 并单击 + 按钮

  1. 您应该将 INStartCallIntent 添加到您的 info.plist 中,如下所示

    <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 无法强制转换为 INStartCallIntent,因此请忽略它。

非常重要在应用程序终止时不会调用场景委托中的继续用户活动功能,因此要在应用程序启动时运行您的意图,您应该添加代码块

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

【讨论】:

  • 在没有 Scene 和 App Delegate 的情况下,如何为 xcode 13 和 swiftui 生命周期编写调用逻辑?
  • 你能解释一下你想做什么吗?
  • 我已经弄清楚了。因为 SwiftUI 必须在此代码中处理所有逻辑:.onContinueUserActivity(NSStringFromClass(INStartCallIntent.self), perform: { userActivity in 但不知道如何将最近通话中的号码分配给用户个人资料,然后点击该号码打开我的应用程序并开始通话
【解决方案2】:

我想让应用在用户按下后拨出电话 最近的电话,但我没有找到任何关于它的信息。

在您应用的Info.plist 中,您必须在NSUserActivityTypes 键中包含INStartAudioCallIntent 和/或INStartVideoCallIntent,并且您的应用委托必须实现-application:continueUserActivity:restorationHandler: 方法来处理启动调用意图。有关详细信息,请参阅 Speakerbox 示例应用程序。

我们可以禁用这个 callkit 功能吗?

如果您没有为通话的CXCallUpdate 设置remoteHandle,则“最近”中的项目将无法按下。

【讨论】:

  • 我可以在系统界面接听电话时打开我的应用程序吗?
  • 我可以通过我的应用程序点击本地通话记录中的条目进行通话。但这不再起作用了。你知道 iOS 11 上是否发生了一些变化吗? NSUserActivityTypes 对我没有任何影响。
  • @GabrielGava 你有更新吗? info.plist 上的 NSUserActivityTypes 似乎无法解决问题。
  • @Legolas 看这里,这为我解决了这个问题:stackoverflow.com/questions/46051359/…
猜你喜欢
  • 2018-05-13
  • 1970-01-01
  • 1970-01-01
  • 2021-09-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多