0

inside AppDelegate I create a UNNotificationRequest with a trigger for 23:58:58pm (midnight) The notification is received and is seen on the notification center screen. so I know it triggers

The app at that time is in the background, but didReceive and willPresent are NOT called at this time.

Having a background task triggers when the app goes into the background, but this may occur at 4pm not midnight.

How can I get a simple function to execute at 23:58:58 each night, esp. when the app is in the background?

Thanks in advance

[DateComponents(hour: 23, minute: 58, second: 58)].forEach {
                    let trigger = UNCalendarNotificationTrigger(dateMatching: $0, repeats: true)
                    let request = UNNotificationRequest(identifier: identifier, content: content, trigger: trigger)
                    center.add(request)
                }
Paulo Campez
  • 702
  • 1
  • 8
  • 24
TheBearF8
  • 375
  • 1
  • 3
  • 14
  • you cannot. You can only execute code after you tap on notification which wakes your app. App cannot execute tasks when they are in background for a long time, which in case OS will kill them . Only certain tasks like downloading data/audio services are available when your app is in background. – Teja Nandamuri Apr 18 '19 at 18:59
  • ^true so to achieve this you can play an audio while app in the background with a frequency which will be silent. However I am not sure Apple will be happy about this approach. – Reaper Apr 18 '19 at 19:26
  • The purpose of the function is in fact to upload data to a server, with sort of an end of day results are.... It was mentioned downloading can it be uploading and if so are there any examples for this Thanks – TheBearF8 Apr 18 '19 at 21:08

0 Answers0