Search code examples
iosswiftcallkit

How to make a fixed name for an outgoing call in CallKit


I'm creating an outgoing one like this and I want to make a fixed name to display in calls, but for some reason remoteAddress is substituted there anyway(

func outgoingCall(remoteAddress: String) {
        mProviderDelegate.incomingCallUUID = UUID()
        let handle = CXHandle(type: .generic, value: remoteAddress)
        let startCallAction = CXStartCallAction(call:  mProviderDelegate.incomingCallUUID, handle: handle)
        startCallAction.contactIdentifier = "Name"
        startCallAction.isVideo = false

        let transaction = CXTransaction()
        transaction.addAction(startCallAction)

        mProviderDelegate.mCallController.request(transaction) { error in
            if let error = error {
            } else {
               
            }
        }
    }

Solution

  • The problem you're encountering seems to be related to how CallKit displays the calling name and address. When you create an outgoing call using CallKit, the CXHandle determines the name or number displayed to the user.

    In the given code, you're setting the CXHandle value to remoteAddress, which means that the remoteAddress will be displayed. The contactIdentifier you've set using startCallAction.contactIdentifier = "Name" is typically used for caller identification but doesn't overwrite the display value set by the CXHandle.

    Solution

    To display a fixed name in outgoing calls, you should set the CXHandle's value to that name:

    let handle = CXHandle(type: .generic, value: "Name")
    

    Additional Information

    And if you still need to keep track of the remoteAddress, you might consider other ways to store or manage it, separate from the UI-related components of CallKit.

    Remember, though, that using a generic handle type with a name might not always make sense, especially if you're dialing a number. If you're working with actual phone numbers, you might want to reevaluate this approach. The goal is to ensure clarity for the user, so they know who they are calling. If you're working with a VOIP service or some other kind of non-traditional phone service where "Name" makes sense as an address, then this approach should be okay.