Created
March 16, 2024 01:44
-
-
Save amosgyamfi/54d9979436278de97092ea92d7da11dd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import SwiftUI | |
import CallKit | |
class IncomingCallViewController: UIViewController, CXProviderDelegate { | |
func providerDidReset(_ provider: CXProvider) { | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// 1. Specify behavior and capabilities of calls. Create an object to control the native call UI for incoming and outgoing calls, including a localized name for the provider, the ringtone to play for incoming calls, and the icon to display during calls.A provider configuration can also set the maximum number of call groups and the number of calls in a single call group, determine whether to use emails and phone numbers as handles, and specify whether to support video. | |
let callUIController = CXProviderConfiguration() | |
// 2. Create a telephony provider. For reporting out-of-band notifications that occur to the system. Initialize with a CXProviderConfiguration object to specify the behavior and capabilities of calls. | |
let callProvider = CXProvider(configuration: callUIController) | |
// 3. Create a provider delegate, specifying an optional queue on which to execute delegate methods. If nil, delegate methods are performed on the main queue. | |
callProvider.setDelegate(self, queue: nil) | |
// 4. Create an objects to be used by the system to communicate changes to calls over time. For example, when a call is started. During a call, other properties may change; for example, a call may be upgraded from audio only to audio and video. | |
let callWatchman = CXCallUpdate() | |
callWatchman.remoteHandle = CXHandle(type: .phoneNumber, value: "+33844202222") | |
callWatchman.hasVideo = false | |
callWatchman.localizedCallerName = "Amos Gyamfi" | |
callWatchman.supportsGrouping = true | |
callProvider.reportNewIncomingCall(with: UUID(), update: callWatchman, completion: { error in | |
if let error = error { | |
print("Failed to report incoming call: \(error)") | |
} else { | |
print("Incoming call reported successfully") | |
} | |
}) | |
} | |
} | |
struct IncomingCallView: UIViewControllerRepresentable { | |
func makeUIViewController(context: UIViewControllerRepresentableContext<IncomingCallView>) -> IncomingCallViewController { | |
return IncomingCallViewController() | |
} | |
func updateUIViewController(_ uiViewController: IncomingCallViewController, context: UIViewControllerRepresentableContext<IncomingCallView>) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment