Hi,
I am trying to create local notification when app runs in background. I have a timer function which can run background(I mean, just click home button when app runs)
In this function, I call these codes,
This function can create notification when I call it after, press home button but, it can not create, I call it when app works in background.
How can I solve this problem?
I am trying to create local notification when app runs in background. I have a timer function which can run background(I mean, just click home button when app runs)
In this function, I call these codes,
Code:
// Creates notification!
func ShowNotification(title:String, body:String){
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .sound, .badge], completionHandler: {didAllow, error in})
let content = UNMutableNotificationContent()
content.title = title
content.body = body
content.badge = 1
content.sound = UNNotificationSound.default()
let trigger = UNTimeIntervalNotificationTrigger(timeInterval: 10, repeats: false)
let request = UNNotificationRequest(identifier: "timer done", content: content, trigger: trigger)
UNUserNotificationCenter.current().add(request, withCompletionHandler: nil)
}
This function can create notification when I call it after, press home button but, it can not create, I call it when app works in background.
How can I solve this problem?
Last edited by a moderator: