Answer the question
In order to leave comments, you need to log in
How to make local notifications in Swift?
Good day!
I figured out how to send pushes using a pusher.
But is it possible to sew pushes into the code itself, so that they would be sent without my knowledge (once an hour for example)? It's just that the point is that pushes with certain phrases would come throughout the day.
I want to install the application only on my devices through test on device.
Answer the question
In order to leave comments, you need to log in
Can. Here is the code:
let content = UNMutableNotificationContent()
content.sound = .default
content.title = "Заголовок"
content.body = "Сообщение"
var dateComponents = DateComponents()
dateComponents.hour = 9
dateComponents.minute = 0
let trigger = UNCalendarNotificationTrigger(dateMatching: dateComponents, repeats: true)
let request = UNNotificationRequest(identifier: UNNotificationRequest.weeklyAlKahID, content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request) { error in
guard error == nil else {
print(error ?? "Error with donate")
return
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question