ios developer
ios developer

Reputation: 3473

make voip call from phone call log in iOS

In my Voip application I am using callkit to receive incoming call. by using the below method:

-(void)reportIncomingCall:(NSUUID*)UDID handle:(NSString*)handle{

I can see the log of this incoming call in call history of my iPhone native call application.

I wanted to make outgoing call from the iPhone native call application. I works for WhatsApp, hangout and etc applications. But, not able to wake up my application when I try calling the user from incoming call log.

- (NSUUID *)reportOutgoingCallContactIdentifier:(NSString *)identifier destination:(NSString *)name telNumber:(NSString *)telnum 

Upvotes: 2

Views: 1932

Answers (2)

Bilal Şimşek
Bilal Şimşek

Reputation: 5943

for swift 5 you should define continueuseractivity function to SceneDelegate.swift

func scene(_ scene: UIScene, continue userActivity: NSUserActivity) {

    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
            }
 
    }
    return
}

please refer this answer

Upvotes: 0

Miki
Miki

Reputation: 921

Basically, you need to create Intents Extension for your target, in order to handle audio calls from native call history.

In Xcode:

File -> New -> Target

Select Intents Extension

Here is the main class for the extension, this is how it should look like

class IntentHandler: INExtension, INStartAudioCallIntentHandling {

func handle(intent: INStartAudioCallIntent, completion: @escaping (INStartAudioCallIntentResponse) -> Void) {
    let response: INStartAudioCallIntentResponse
    defer {
        completion(response)
    }

    // Ensure there is a person handle
    guard intent.contacts?.first?.personHandle != nil else {
        response = INStartAudioCallIntentResponse(code: .failure, userActivity: nil)
        return
    }

    let userActivity = NSUserActivity(activityType: String(describing: INStartAudioCallIntent.self))

    response = INStartAudioCallIntentResponse(code: .continueInApp, userActivity: userActivity)
    } 
}

Than, you need to provide the URLScheme for your app in order to start a VoIP call when the app delegate receives the openURL

Here is the extension for the NSUserActivity to help you detect the start call intent

import Intents

@available(iOS 10.0, *)
protocol SupportedStartCallIntent {
    var contacts: [INPerson]? { get }
}

@available(iOS 10.0, *)
extension INStartAudioCallIntent: SupportedStartCallIntent {}

@available(iOS 10.0, *)
extension NSUserActivity {

    var startCallHandle: String? {
        guard let startCallIntent = interaction?.intent as? SupportedStartCallIntent else {
            return nil
        }
        return startCallIntent.contacts?.first?.personHandle?.value
    }

}

You also need to register your URL scheme in your target settings:

Xcode target settings, select Info card, and on the bottom URL Types, select + to add new type and give it a name, like VoIPCall

In AppDelegate override the following function

func application(_ application: UIApplication,
               continue userActivity: NSUserActivity,
               restorationHandler: @escaping ([Any]?) -> Void) -> Bool {

    if userActivity.startCallHandle {
        // START YOUR VOIP CALL HERE ----
    }
    return true
}

Upvotes: 5

Related Questions