供日后参考;
-
呼叫工具包提供商配置应具有此通用和电话号码类型列表
config.supportedHandleTypes = [.generic,.phoneNumber]
-
Callkit 更新远程句柄应该像下面这样初始化
update.remoteHandle = CXHandle(type: .generic, value:String(describing: payload.dictionaryPayload["caller_id"]!))
3.您应该将 Intents.framework 添加到您的项目中,方法是选择 project>target>Build Phases> Link Binary With Libraries 并单击 + 按钮
-
您应该将 INStartCallIntent 添加到您的 info.plist 中,如下所示
<key> NSUserActivityTypes </key>
<array>
<string>INStartCallIntent</string>
</array>
-
对于 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
}
}
}
}