Schedule a background backup of CoreData to cloudKit weekly

I have an app that is able to make a backup of the core data to cloudkit if the user does it manually with the app in the foreground. But my idea is to give to the user the option of doing an automatic backup of the data every week (or 15 days or so...). Of course this backup should be done in background mode (maybe in the night at 2:00 am or something) but I don't find the right way to execute the scheduled code while the app is in the background or closed.


I'm thinking about doing it with the Background App Refresh calling

setMinimumBackgroundFetchInterval:
method of
UIApplication
at launch time and implement the
application:performFetchWithCompletionHandler:
method to upload the data to cloudKit, but I'm not sure if this is the right way.


Any suggestions?