I need to fire a local notification which is decided by the end user.
I provide 8/9 options to the user for selecting at least one of below time duration.
20 minutes , 25 minutes till 60 minutes.
Again user provides the starting time.
Consider the time duration is morning 6.28 to night 11.37
The expected tasks performed by the local notification is
show a local notification after every 20 minutes between the duration of 6.28 am to 11.37 pm.
first notification will come at 6.48 am. And till its 11.37 . No notification should come after 11.37.
Is there any way ?
UILocalNotification has a repeatInterval property which you'd normally use to create recurring notifications. Unfortunately, it does not offer the flexibility you need - you can use repeat intervals of 1 minute, 1 hour, but nothing in between. And there's also no 'end date' option.
The only other option is to create multiple notifications, each firing only once. Keep in mind that there is a maximum of 64 notifications per app. With a minimum interval of 20 minutes, this covers 21 hours and 20 minutes of notifications.
UILocalNotification has repeatInterval property.
UILocalNotification *localNotif = [[UILocalNotification alloc] init];
localNotif.repeatInterval = NSMinuteCalendarUnit;
Try above code.
Related
How to schedule the notification based on the incremental time span
10 min, 10 hours, 20 hours, 1 day, 5 days, 1 week, 1 month, 5 month, 1 year, 5 years, 10 years.
Notification Message:
for 10 min
You have completed Successfully 10 min
for 10 hours
You have completed Successfully 10 hours
From the little information provided, I would proceed like the following :
Look at NSUserDefaults to see what was the previous iteration
Define a start time based on that previous iteration (if any)
Schedule a local notification using the Local Notifications provided in the iOS SDK.
Save that same date/time in the NSUserDefaults.
Once we reach that time, the notification will be sent (by iOS), and we can execute code to repeat this sequence.
Here are my problems :
Schedule local notifications between two dates every specific day of the week . example : between march 1 and march 20 every sunday
I have more than 64 local notifications to set which is the limit .
For the first problem i know there is repeatIntervals which i can set to fire notification every Sunday but how can i set them between two dates ? Do i need to calculate manually and find all the Sundays between March 1 and 20 and then set it or there is something better ?
Use the NSCalendar to get the specific dates, put in an array, and pass to the scheduleLocalNotification.
In this topic you can have a sample code of how to do it.
I am working on Homekit based application, In That Homekit supports Triggers which fires on a specific date and it can be scheduled to fire repetitively by minutes, hour, days, week and month.
I want to schedule the Trigger to fire on specific days which is selected by user like mon,tue,wed,thu only or weekends (sat, sun).
I have set the recurrence using NSDateComponents but not able to set the repeat it for specific days.
Is there any way to schedule it by recurrenceCalendar object?
HMTimerTrigger's method has this object which can be passed as parameter.
HMTimerTrigger *newTrigger = [[HMTimerTrigger alloc] initWithName:#"Morning Schedule"
fireDate:self.fireDate
timeZone:nil
recurrence:recurranceComp
recurrenceCalendar:nil];
I just want to schedule a same local notification in Swift. For example I just want to schedule a message saying "It's time to calculate your bill for this month" and I want to send this same message again next month.
How to do this kind of local notification in Swift?
I have referenced followings but was not able to schedule a same message in next month ...
//http://thecodeninja.tumblr.com/post/89942124085/notifications-in-ios-8-part-1-using-swift-what-is
//From String to NSDate in Swift
UILocalNotification has a repeatInterval property that lets you specify how often the notification should repeat. Note that this is an NSCalendarUnit, not just an arbitrary number, so you can only make a notification repeat once per calendar unit (second, minute, hour, day, week, month, etc.). See the NSCalendarUnit documentation for more options.
For example, you can make a notification repeat every month with:
notification.repeatInterval = .CalendarUnitMonth
I'm not sure how this would work, but what I'd like is something similar to Apple's alarm clock that comes with the iPhone. It basically just lets you pick a time of an alarm, name the alarm, and then you can choose how often you want it to repeat (Sunday - Saturday). Based on what you choose, the alarm fires once, or at a repeated interval.
In my Core Data model, I wasn't sure how to model that. If I were thinking in terms of just plain old objects, I would think I would have some alarm object, and one of its properties would be an array. In that array I could have the day values of Sunday-Sautrday. Then when a new alarm object is created, I would schedule a UILocalNotification for the time selected, and the days chosen. To model that in terms of database objects, I'm not sure what I'm supposed to do. I was thinking something like:
Alarm - (name/string)
Day - (Sunday - Saturday/represented by integers 0-6, 1 to many relationship from Alarm to Day)
Assuming that is ok in the database, then I'm not sure how I should go about scheduling the UILocalNotifications since I thought you could only have 64 per app. I'm thinking that I could have some mechanism to schedule the first 64 alarms possible, then when the app is opened, it would just reschedule the next upcoming 64 events. Is that how I would do that? Thanks.
Using 2 entities is overkill. I would just have the Alarm entity and have a single integer attribute on it to hold the alarm days. Outside of the entity, I would have an enumeration which defines how the alarm days number is interpreted. Something like:
typedef AlarmDays {
Monday = 0,
Tuesday = 1 << 0,
Wednesday = 1 << 1,
Thursday = 1 << 2,
Friday = 1 << 3,
Saturday = 1 << 4,
Sunday = 1 << 5
} AlarmDays;
Then you can test which days it should be on using:
if (alarm.alarmDays & Monday) {
// the alarm should fire on mondays
}
And you can use the features of UILocalNotification, such as repeatInterval so you don't need to explicitly add gazillions of notifications to the system.