Several things to keep in mind:
If you want to work with PUSH notifications of an APNS , the delegate method you are using is not the correct one.
If what you want are local notifications, in iOS 10 , the UILocalNotification
library is obsolete. The UserNotifications
library is used. Below I leave a code that schedules a user notification. It approaches or moves away from a specific geographical point, I hope it serves as a reference.
When I schedule this notification, it is displayed and the method you comment on your question is launched.
func createLocationNotifation(
title: String,
text: String,
location: CLLocation,
identifier: String,
onExit: Bool
) {
let coordinate = CLLocationCoordinate2DMake(
location.coordinate.latitude,
location.coordinate.longitude
)
let region = CLCircularRegion(
center: coordinate,
radius: 100.0,
identifier: identifier
)
region.notifyOnExit = onExit
region.notifyOnEntry = !onExit
let trigger = UNLocationNotificationTrigger(region: region, repeats: false)
let content = UNMutableNotificationContent()
content.title = title
content.body = text
content.sound = UNNotificationSound.default()
content.badge = 1
let request = UNNotificationRequest(
identifier: identifier,
content: content,
trigger: trigger
)
let center = UNUserNotificationCenter.current()
center.add(request, withCompletionHandler: nil)
}