Assuming your notification is working correctly, you can match UNUserNotificationCenterDelegate to handle the call action.
Sort of:
func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { if response.actionIdentifier == "call" { let body = response.notification.request.content.body if let url = URL(string: "tel://\(body)") { UIApplication.shared.open(url, options: [:], completionHandler: nil) } } }
The body constant will be set to the phone number you want to "open".
In addition, it is important to note that this should be verified on a real device. Opening the tel scheme does nothing in the simulator.
UNUserNotificationCenterDelegate reference: https://developer.apple.com/reference/usernotifications/unusernotificationcenterdelegate
EDIT:
You do not call the delegate method. Instead, you implement it. The delegate method is called by UNUserNotificationCenter .
To get this working, it is important to make sure that you assign the UNUserNotificationCenter.current() delegate property to the class that will conform to the UNUserNotificationCenterDelegate protocol.
For example, if you are processing your notification in your AppDelegate , you might have something like the following method:
func callNotification() { let center = UNUserNotificationCenter.center()
The above method will be responsible for defining your notification and planning it. For brevity, I left all the code that will determine the notification, as you indicated that this works. Instead, you should notice that the delegate property is set to self .
Then, in the extension, you must make AppDelegate compatible with UNUserNotificationCenterDelegate and implement the necessary methods.
extension AppDelegate: UNUserNotificationCenterDelegate { func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) { if response.actionIdentifier == "call" { let body = response.notification.request.content.body if let url = URL(string: "tel://\(body)") { UIApplication.shared.open(url, options: [:], completionHandler: nil) } } } }
Now that your AppDelegate complies with the UNUserNotificationCenterDelegate protocol and you set self ( AppDelegate ) as the UNUserNotificationCenter delegate, your implementation of the userNotification(_:didReceive:withCompletionHandler:) will be called.