app-starlock/ios/Runner/LCKBridge.swift
2025-07-02 17:11:39 +08:00

60 lines
2.5 KiB
Swift

import Foundation
import UIKit
#if USE_CALLKIT
import CallKit
#endif
import LiveCommunicationKit
@objc(LCKBridge)
class LCKBridge: NSObject {
// CallKit
@objc(presentCallInterfaceWithCallKit:)
class func presentCallInterfaceWithCallKit(_ callerName: NSString) {
#if USE_CALLKIT
let providerConfiguration = CXProviderConfiguration(localizedName: callerName as String)
providerConfiguration.supportsVideo = false
providerConfiguration.maximumCallsPerCallGroup = 1
let provider = CXProvider(configuration: providerConfiguration)
let update = CXCallUpdate()
update.remoteHandle = CXHandle(type: .generic, value: callerName as String)
update.hasVideo = false
provider.setDelegate(nil, queue: nil)
provider.reportNewIncomingCall(with: UUID(), update: update) { error in
if let error = error {
print("CallKit来电弹窗失败: \(error.localizedDescription)")
} else {
print("CallKit来电弹窗成功")
}
}
#endif
}
// LiveCommunicationKit
@objc(presentCallInterfaceFromRootVC:callerName:)
class func presentCallInterfaceFromRootVC(_ rootVC: UIViewController, callerName: NSString) {
#if !USE_CALLKIT
if #available(iOS 17.4, *) {
// ConversationManager
let config = ConversationManager.Configuration(
ringtoneName: "notes_of_the_optimistic",
iconTemplateImageData: UIImage(named: "AppIcon")?.pngData(),
maximumConversationGroups: 1,
maximumConversationsPerConversationGroup: 1,
includesConversationInRecents: false,
supportsVideo: false,
supportedHandleTypes: [.generic, .phoneNumber, .emailAddress]
)
let manager = ConversationManager(configuration: config)
let local = Handle(type: .generic, value: callerName as String, displayName: callerName as String)
let update = Conversation.Update(localMember: local, members: [local], activeRemoteMembers: [local])
Task {
do {
try await manager.reportNewIncomingConversation(uuid: UUID(), update: update)
print("成功报告新来电")
} catch {
print("报告新来电失败: \(error.localizedDescription)")
}
}
}
#endif
}
}