Make VoIP call on iOS with Swift 3

1

I'm trying to make IP voice calls on iOS with Swift (using Apple's SpeakerBox) but I do not know where the local network I want to use is added to make the call, the code needed to do it and the necessary configuration for the Xcode and that everything goes correct.

I leave the code where I'm stuck where I should add the network service.

// Trigger the call to be started via the underlying network service

func provider(_ provider: CXProvider, perform action: CXStartCallAction) {

    // Create & configure an instance of SpeakerboxCall, the app's model class representing the new outgoing call.
    let call = SpeakerboxCall(uuid: action.callUUID, isOutgoing: true)
    call.handle = action.handle.value

    /*
     Configure the audio session, but do not start call audio here, since it must be done once
     the audio session has been activated by the system after having its priority elevated.
     */
    configureAudioSession()

    /*
     Set callback blocks for significant events in the call's lifecycle, so that the CXProvider may be updated
     to reflect the updated state.
     */
    call.hasStartedConnectingDidChange = { [weak self] in
        self?.provider.reportOutgoingCall(with: call.uuid, startedConnectingAt: call.connectingDate)
    }
    call.hasConnectedDidChange = { [weak self] in
        self?.provider.reportOutgoingCall(with: call.uuid, connectedAt: call.connectDate)
    }

    // Trigger the call to be started via the underlying network service.
    call.startSpeakerboxCall { success in
        if success {
            // Signal to the system that the action has been successfully performed.
            action.fulfill()

            // Add the new outgoing call to the app's list of calls.
            self.callManager.addCall(call)
        } else {
            // Signal to the system that the action was unable to be performed.
            action.fail()
        }
    }
}

func startSpeakerboxCall(completion: ((_ success: Bool) -> Void)?) {


// Simulate the call starting successfully
    completion?(true)

    /*
     Simulate the "started connecting" and "connected" states using artificial delays, since
     the example app is not backed by a real network service
     */

    print("LLAMANDO....")
    DispatchQueue.main.asyncAfter(wallDeadline: DispatchWallTime.now() + 3) {
        self.hasStartedConnecting = true

        DispatchQueue.main.asyncAfter(wallDeadline: DispatchWallTime.now() + 1.5) {
            self.hasConnected = true
        }
    }

}

    
asked by David Lopez 07.03.2017 в 09:59
source

0 answers