Get Local Notification every sunday if events is there in that week - ios

I am scheduling a local notification which is give notification on every Sunday. But I want if next Week have any event then i will receive notification on Sunday. if there is no event in that week than skip notification on Sunday.I have Event Array.I will set
localNotification.repeatInterval = NSCalendarUnitWeekday;
so i receive notification On Sunday.how I skip it..??

Related

Repeat Notifications monthly on specific day

I want to repeat notifications monthly on a specific day, but my concern is, what if the user chooses the 31? Then the Notification would only fire every 2 months and never in February?
Because the day component would not match.
Is it possible to set the day to the last day of the month, so when for example February is the next month and the user selected the 31. then it would fire on the last day of February?
I could go the non repeating way and add the notifications manually, but then i would have to face the 64 scheduled notification limit.
Thanks for your help in advance.
The Calendar module is the way to go. Handling dates manually can get very tricky.
import Calendar
let selectedDate = "31/01/2020"
// Convert string to Date
let dateF = DateFormatter()
dateF.dateFormat = "dd/MM/yyyy"
let myDate = dateF.date(from: selectedDate)!
// Advancing date by a month, to get end of next month.
Calendar.current.date(byAdding: .month, value: 1, to: myDate) // "Feb 29, 2020 at 12:00 AM"
In the example above, you can see how to advance date by a month.
If the user chooses say the 31 of a month, the calendar automatically calculates the end of the next month accurately, even if it has only 28, 29, 30 or 31 days.
One option would be to use remote notifications and handle them on a server. This would involve a bit more work and a server, but it is more flexible and allows you to change the notifications without the user needing an app update. Link to the Apple Doc for Remote Notifications.
The other option would be the use Calendar.
When you do your logic to send the notification, you can test if today is the last day of the month. If the user chooses to get the notifications on the 31st, and say today is the last day of the month and is the 30th, you can still send the notification because you know there isn't a 31st in this specific month.

How to schedule local notification varying time slot?

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.

HMTimerTrigger for selected days using NSCalendar?

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];

How to schedule a same local notification in swift

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

UILocalNotification on particular day like sunday repeat by every 2 week

I want to repeat UILocalNotification particular day alternatively. I mean if it's fire on sunday 7:00 am then second notification should be fire on next to next sunday 7:00 am.
Is this possible?
Can any one help me.
Thanks!
You can make a counter of hours's and save it in NSUserDefaults
if (counterOfHours % 336 == 0) then push notification, remember to set counterOfHours to 0 :)
Cheers S.

Resources