I would like to schedule a local notification to fire at 7pm everyday IF a certain condition is met (the user hasn’t entered daily data).
How do I go about doing this?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Just break it up into 3 cases:
In case 1, you set up a notification to go off at 7pm today, and then repeat every day.
In cases 2 and 3, you set up a notification to go off at 7pm tomorrow, and then repeat every day.
The code to create and schedule the notification looks like this:
Of course, if you set up an alert for 7pm today, then the user opens the app and enters data before 7pm, the notification for today needs to be cancelled.
Alternatively (this is what I did in a similar situation), you can cancel all the notifications with
[[UIApplication sharedApplication] cancelAllLocalNotifications];and set them up again from scratch based on the application state every time the app is about to go into the background (i.e., inUIApplicationapplicationDidEnterBackground:. This is simpler since you don’t have to think about what notifications you set up before.