You have two options:
- Create a repeating Local notification that fires every minute.
func repeatNotification() {
let content = UNMutableNotificationContent()
content.title = "It's Time!!"
content.body = "This is a body"
content.categoryIdentifier = "my.reminder.category"
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 60.0, repeats: true)
let request = UNNotificationRequest(identifier: "my.reminder", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request) { (error) in
if let error = error {
print("error in allowing notifications: \(error.localizedDescription)")
}
}
print("added notification:\(request.identifier)")
}
When the notification is fired you will get a callback in AppDelegate userNotificationCenter:willPresentNotification:withCompletionHandler:
Your second option is to register as a background location app. Basically you will ask your users to allow location all the time even when not using your app. This will allow you to run in the background indefinitely but it comes at the cost of draining battery power super fast.
If choose this option, you need to setup a location manager and ask you users to always allow location when prompted.
They you will get location updates in locationManager(_:didUpdateLocations:) every X interval.