iOS: Timer or Local Notification for everyday repetitive action - ipad

I want to display multi-buttons alertview to user everyday twice a day. They can take an action or snooze the action. If they snooze the action then the same alertview will appear again after 10 minutes. Could anyone please tell me what should be the best way to implement this. Thanks.

Local notifications are what you want here. NSTimer only runs while your application is running, which won't (always) be the case.
See this discussion Snooze local Notification for further information.

Related

iOS Notification based on time of day

I have published a diet planning iOS App. I've had users ask if they could have notifications pop up on there phone when it's time for them to eat a meal. For example, if they set their set their wake up time on the App at 7am, every 3 hours an alert would pop up and remind them to eat, so would be 10am, 1pm, 4pm...
Currently I have not implemented push notifications. I have been ready about iOS Push Notification Services, and I'm thinking that is there an easier way to accomplished this? Some sort of scheduled notification. I feel I shouldn't need any network integration to perform this fairly simple task. Any suggestions are welcome. thank you
It looks like UILocalNotification is exactly what you want.
From the linked documentation:
After creating a UILocalNotification object, schedule it using either the scheduleLocalNotification: or presentLocalNotificationNow: method of the UIApplication class. The scheduleLocalNotification: method uses the fire date to schedule delivery; the presentLocalNotificationNow: method presents the notification immediately, regardless of the value of fireDate. You can cancel one or more local notifications using the cancelLocalNotification: or cancelAllLocalNotifications method of the UIApplication object.

Do UIAlertView have fireDate like UILocalNotifications?

I have a task to create an alarm app. I manage to make the alarm sound using Local Notification.
The problem is that I can't make buttons(actions) on the local notification for "Snooze" and "Okay". I also searched how to implement Interactive Local Notification but I can't follow it. What I'm thinking now is to create an alertView with buttons instead of Local Notification in sounding the alarm. Is there a fireDate function in alertView than I can use to make it happen?
No alertview itself dsnt have any firedata property
But you went the right direction as when you want UIInteractive Notification to make a interactive notificaiton without the application being opened.
Here is a link to a much easier Objective C tutorial for Interactive Notifications.
UIAlertView is only used for displaying alerts while the user is using the app. The alert view that's displayed to a user (or, more likely, a banner), is presented by the operating system. You can follow this tutorial on how to create local notifications with actions. Good luck!
for "How to Implement iOS8 Interactive Notification"
you can check this,
link
Here all the steps are mentioned you want to make local notifications...

UILocalNotifications algorithm

I have a problem scheduling UILocalNotifications.
My case is this: when user selects motivation category there is a dialog screen where he selects how many times in a day, week, month, motivation message should be presented to him. Then he selects time period: a day, week or a month. A motivation category has messages, and every category has different number of messages.
So my question is: how should i schedule those notifications? Main problem i think is that there can be more than one category. Can someone tell me how to do this?
I know that i cant schedule more than 64 notifications, so i cant schedule all notifications when category is selected. And i know i could reschedule notifications in
application:didFinishLaunchingWithOptions:
or
application:didReceiveLocalNotification:
I hope i have been clear about my problem.
First write a function that manages the local notifications
that is it has to check if there are 64 notifications scheduled if not then you may add some notification.(you have to handle DB part well for example setting the flags correctly)
Call the function in application:didFinishLaunchingWithOptions: just in case some notifications are expired or missed
You have to call the function in all the places where local notification is handled.
The user taps a custom action button in an iOS 8 notification.
In this case, iOS calls
application:handleActionWithIdentifier:forLocalNotification:completionHandler:
You also get the local notification object, so that you can retrieve any information you need to handle the action.
The user taps the default button in the alert or taps the app icon.
The system launches the app and the app calls its delegate’s method, passing in the local notification object
application:didFinishLaunchingWithOptions:
The notification is delivered when the app is running in the foreground.
The app calls the UIApplicationDelegate method
application:didReceiveLocalNotification:
Reference1:
Reference2:
I hope this helps.
If it doesn't cover your problem feel free to ask doubts
It works as pool when you utilized all your available notifications then you need to reschedule the free notifications in
application:didReceiveLocalNotification: but every time you are gonna reschedule you can find next notification to user that could be in today, tomorrow. Whenever you are in application:didReceiveLocalNotification: findout when to notify next and schedule.

What is the best way to modify a UILocalNotification after it has fired?

I understand that you cannot modify a UILocalNotification after it has been scheduled. My problem is that I want to set the .repeatInterval so that it fires at a specific time once per day. However I want the content to change every day. So the user sets the alarm to fire at 10AM, and every day at 10AM gets an alert with different content without having to reset their alarm.
I was thinking about canceling and rescheduling when didReceiveLocalNotification was called but that requires the user to launch the app before the next scheduled alert. Is there a way to call a method immediately after the alert is fired?
Unfortunately you have no certain way of knowing that a local notification has fired unless your app is frontmost at the time it fires.
And, as you say, you cannot change a notification.
So I think your best bet is do not use repeating notifications. Set up a different single notification for each day, say, two weeks ahead, with different messages for each, and hope the user runs the app between now and then so that you can "refresh" the queue, as it were. Maybe make only the last one repeating, just in case, so that the notifications never stop - but of course then the message will be same each time. But there's nothing you can do about that. You can't force the user to run the app.

distinguish whether app was launched through the UILocalNotification

I am working on a alarm clock app and I've been stuck for the last couple of days. I was hoping you guys could help out.
My question is;
Is there any way to distinguish whether the app was opened through the UILocalNotification alertAction or just opened regularly?
I want to use the UILocalNotification to create a snooze feature, so if the app is opened by the user tapping on the action button on the LocalNotification, a snooze mechanism will launch (but obviously i don't want that to launch if the user regularly opens the app to set the time or something)
Thank you so much for your help!
Yes this is possible as described in the UILocalNotifaction class reference
In the
application:didFinishLaunchingWithOptions:
method the application delegate can
obtain the UILocalNotification object
from the passed-in options dictionary...
Therefore you can check the options dictionary to see if the notification is present. If it is then that's how the app was launched.

Resources