-2

I created a scene to present weekly goals. I count up a variable each second a user is using my App and save it to the UserDefaults. How can I reset(Set to 0) each Monday at 6PM in order to reset the 'weekly' goal automatically in the background whether the App is terminated or not? I would also include a Usernotification. Can I even execute code within the Usernotification? I'm using SWIFT.

Thanks for any help!

Dilan
  • 2,610
  • 7
  • 23
  • 33

2 Answers2

0

If the app is not running, it isn't running, and nothing can guarantee that it will do something at a certain time except sending a Push Notification from your server at that time.

However, it would be better to revise your goals. Keep in mind that if the user sees your app at all, the user is using your app. So you can always detect the situation and change whatever needs to be changed whenever the user foregrounds/launches the app. The effect will be exactly the same.

matt
  • 515,959
  • 87
  • 875
  • 1,141
0

It may work. When users begin any event (e.g., open your app, sign in, or click a button), get the current date and save the date to a variable. Then put some code to compare the date in the variable with a current time in each Viewcontroller. When the current date is different from the date in the variable, (a) update the variable with the current date and (b) activate the codes that we want to execute using "if" statement. It works for me.

Davd
  • 21
  • 1
  • 7