-1

I want to get notification when app is terminated to notify users that you need to keep app running to get app updates.

I also want to repeat notifications every 72 hours if app is not running.

For now, I have implemented local notification however, I am not able to repeat notifications. Moreover, when I reboot device and app is in background, I do not get notification until I relaunch app manually.

What is the best solution for this scenario, do I need to implement Push notification or is it possible with local notification?

Would anybody mind to help me, I will really appreciate it!

Thanks in advance!

1 Answers1

0

You need to use BGAppRefreshTask in conjunction with a BGTaskScheduler. First, add a new capability to your target: Background Modes and select Background fetch. Next, Register your task identifier in the Info.plist under Permitted background task scheduler identifiers. e.g. UpdateApp

further explanation and details: Apple Background Tasks

you can use this for your current idea of notifying the user every 72 hours, or you can just perform the app updates in the background using a BGProcessingTask instead of a BGAppRefreshTask if the updates require more time to complete than a simple refresh task.

ɯɐɹʞ
  • 1,040
  • 11
  • 17
  • My app is getting notifications in background after adding code: bgTask = UIApplication.shared.beginBackgroundTask(withName:"MyBackgroundTask", expirationHandler: {() -> Void in UIApplication.shared.endBackgroundTask(self.bgTask) self.bgTask = UIBackgroundTaskIdentifier.invalid }) However, when my app is in background and I reboot the device, then I am not getting notifications until I re-open app manually. I do not want to open app after reboot as it is already in background. – Rajput Nancy Katal Jan 19 '23 at 19:43
  • the background task will not be performed when an app is foregrounded. so you need to schedule tasks accordingly, like as the app enters the background, and after the initial task is performed, reschedule as part of that task. – ɯɐɹʞ Jan 19 '23 at 20:15
  • 1
    Okay, but will this resolve problem for reboot device that I am not getting notifications after rebooting device when app is already in background and I do not launch it manually? – Rajput Nancy Katal Jan 19 '23 at 20:19