How to detect a call made using openUrl() is ended in ios - ios

In my application, there is an option to make a call when the user taps a phone number. I'm implementing this as shown below:
if let url = URL(string:"tel://\(String(describing: Util.checkForNullString(contactNo)))"), UIApplication.shared.canOpenURL(url){
if #available(iOS 10, *) {
UIApplication.shared.open(url)
} else {
UIApplication.shared.openURL(url)
}
}
I want to do another action soon after the user finishes the call. But how to get notified when the call is finished ?

Related

iOS - Control over "${App} wants to open ${Another App}" dialog

In my app, I have functionality where the user could open another app lets call it as 'App2'. If App2 is not present on the device, then user will be present with an app not available alert that I created, lets call this as Alert1.
However if App2 is present on the device and user tries to open it, Apple's "${App} wants to open App2" dialog is presented. If user clicks 'Cancel' on this, the callback executes my code to present Alert1.
I don't want my app to display Alert1 when user clicks 'Cancel' on Apple's dialog. Is there a way to control Apple's dialog?
Below is my code:
if let url = urlComponents.url {
UIApplication.shared.open(url, completionHandler: { success in
if !success {
showAppNotAvailableAlert(url.absoluteString, actionLabel: action.label)
}
})
return
}
try
if let url = urlComponents.url {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, completionHandler: { didURLOpen in
if !didURLOpen {
debugPrint("User pressed cancel button")
}
})
}
else {
showAppNotAvailableAlert(url.absoluteString, actionLabel: action.label)
}
return
}
idea is to check if app exists by using canOpenURL, if it exists then try to open the app and handle error in completion block

Open settings URL from user notification?

Opening settings URLs works for me from a UIAlertController but not from a UNUserNotificationCenter notification. Both approaches use the same URLs and the same code, namely this function:
func open() {
if let url = self.url {
if UIApplication.shared.canOpenURL(url) {
UIApplication.shared.open(url, completionHandler: { (success) in
Log.log("Opened settings url: \(url), \(success)", true)
})
}
}
}
My logging line shows the completionHandler gets called with true from the alert and false from the notification. At first I thought it might be an issue with the phone being locked, but I also got false through a notification interacted with on the home screen.
What do I need to do to get this to work from notifications?
Try it with ".foreground" in options while declaring UNNotificationAction.
(this action should cause the application to launch in the foreground.)

Can we make carrier network call by using callkit in swift ios

I am trying to make a phone call from my application for that I want to use callkit, it is possible to make a phone call(non VOIP) over carrier network using callkit? so that I can get the call status and last call time.
I am able to make the voip call and also able to see the call log in phone but didn't found a way to read phone call logs.
Oops unfortunately not, the only thing you can do is to pass the contact no to the default iOS phone app if you want to make a non-voip call
func dialNumber(number : String) {
if let url = URL(string: "tel://\(number)"),
UIApplication.shared.canOpenURL(url) {
if #available(iOS 10, *) {
UIApplication.shared.open(url, options: [:], completionHandler:nil)
} else {
UIApplication.shared.openURL(url)
}
} else {
// add error message here
}
}
Use this function to make a carrier network call using swift 4.

CallKit issue with call holding (iOS 10)

I have an issue with CallKit API on iOS 10.3.3 and lower iOS versions.
My configuration supports call holding and grouping, here is the snippet.
let configuration = CXProviderConfiguration(localizedName: applicationName)
configuration.supportsVideo = supportsVideo
configuration.supportedHandleTypes = [.phoneNumber]
configuration.maximumCallGroups = 2
configuration.maximumCallsPerCallGroup = 3
On iOS 10, CallKit drops the call when app requests setHeld action for call.
Here is the snippet of setHeld call action request.
public func performSetCallOnHoldAction(_ call: Call, isOnHold: Bool) {
let setHeldAction = CXSetHeldCallAction(call: UUID(uuidString: call.callUUID)!, onHold: isOnHold)
let transaction = CXTransaction()
transaction.addAction(setHeldAction)
requestTransaction(transaction)
}
And finally, here is the CXProvider delegate method, which completes the hold/unhold action for call:
func provider(_ provider: CXProvider, perform action: CXSetHeldCallAction) {
// Retrieve the Call instance corresponding to the action's call UUID
guard let call = CallList.sharedInstance().call(withUUID: action.callUUID.uuidString) else {
action.fail()
return
}
// Perform PJSUA set held action
if action.isOnHold {
Pjsua2Wrapper.sharedInstance()?.holdCall(withCallUUID: call.callUUID, completion: { (error) in
(error != nil) ? action.fail() : action.fulfill()
})
} else {
Pjsua2Wrapper.sharedInstance()?.unholdCall(withCallUUID: call.callUUID, completion: { (error) in
(error != nil) ? action.fail() : action.fulfill()
})
}
}
Note that I use Pjsip to perform a hold/unhold action and inside a completion block I call action.fulfill() or action.fail(), depending wether psjip returns the error.
In application GUI, there is a toggle swap button, which calls function to perform CXSetHeldCallAction on CXCallController.
On iOS 11.0 everything works perfectly, but on iOS 10, when you press that toggle button, the call which is supposed to be set on hold, gets ended by the CXProvider for some reason (CXProvider responds with CXEndCallAction).
I have looked in debugger for requestTransaction method wether it returns transaction error, but there is no error in requesting a transaction to call controller.
Does anyone have an idea what is wrong, or something that I can try out to fix this issue?

Add function for cancel in UIAlert of Phone Call function

I have a function that places a phone call when a button is pressed.
private func callNumber(phoneNumber:String) {
if let phoneCallURL = URL(string: "tel://\(phoneNumber)") {
let application:UIApplication = UIApplication.shared
if (application.canOpenURL(phoneCallURL)) {
application.open(phoneCallURL, options: [:], completionHandler: nil)
}
}
}
I want to add some functionality if the users hit cancel when the alert pops up to confirm the call. How would I do that?
According to this question: Prompt when trying to dial a phone number using tel:// scheme on iOS 10.3
This alert is actually a bug in iOS 10.3 and should be removed at some point in the future. It isn't supposed to come up for "tel:" links in native apps.
That said, I don't believe there is a way to detect the alert and how the user interacts with it.

Resources