[ad_1]
Learn how to ship notification when api modifications its knowledge? I get knowledge from url. When the info at this deal with modifications, the person should obtain it. I attempted to make use of “UNTimeIntervalNotificationTrigger(timeInterval: 60, repeats: true)” but it surely sends the notification with out change.
func apiNotification(urlString:String){
if let url = URL(string: urlString) {
if let knowledge = strive? Information(contentsOf: url) {
parse(jsonData: knowledge)
}
}
}
personal func notificationSend(id:String, title: String, introtext: String){
let content material = UNMutableNotificationContent()
content material.subtitle = title
content material.physique = introtext
content material.sound = UNNotificationSound.default
let set off = UNTimeIntervalNotificationTrigger(timeInterval: 30, repeats: false)
let uid = UUID.init().uuidString
let request = UNNotificationRequest(identifier: uid, content material: content material, set off: set off)
UNUserNotificationCenter.present().add(request) { (error) in
if let error = error {
print("Error (error.localizedDescription)")
} else{
print("Notification Register Success")
print("===================================")
}
}
}
personal func parse(jsonData: Information) {
do {
let decodedData = strive JSONDecoder().decode(ApiData.self, from: jsonData)
notificationSend(id:decodedData.id, title: decodedData.title, introtext: decodedData.introtext)
} catch {
print("decode error")
}
}
API JSON:
{
"id": "176",
"title": "Notification title 1",
"introtext": "Notification introtext 1",
}
Modified JSON API:
{
"id": "177",
"title": "Notification title 2",
"introtext": "Notification introtext 2",
}
Please assist me
[ad_2]
