How to set custom repeat interval for Nslocal notification .....?

I am new to iphone development. I'm trying to use NslocalNotification in my project. I need to give Remeinder every 2Hours or every two days or every two months, etc. I am currently using NslocalNotification Repeat Interval. Work every minute for every hour using Nscalender ....

NSString *InterVal=[freQuencyArr objectAtIndex:index-2]; NSString *InterValType=[freQuencyArr objectAtIndex:index-1]; if(![InterVal isEqualToString:@"Every"]) { result=[InterVal intValue]; }else result=1; if([InterValType isEqualToString:@"Day"]){ notification.repeatInterval= NSDayCalendarUnit; }else if([InterValType isEqualToString:@"Week"]){ notification.repeatInterval= NSWeekCalendarUnit; } else if([InterValType isEqualToString:@"Month"]){ notification.repeatInterval= NSMonthCalendarUnit; }else if([InterValType isEqualToString:@"days"]){ notification.repeatInterval=result*24*60*60; } 

here If the result is 2, it depends on IntervalType I Need Notification it does not work with me

  if([InterValType isEqualToString:@"days"]){ notification.repeatInterval=result*24*60*60; } 
+6
source share
3 answers

@Srinivas:

If you look at the link that I posted in this answer, you will find out that I have tried all possible solutions here to try and do what you want at the moment.

I tried to implement all this in my application, but it will not work.

I am afraid to say it, but it is impossible. It allows you to set unit NSCalendarUnit objects as a repeat interval.

I invested almost 2 months (I asked a question in December 2010 and answered it myself in February 2011) to try to implement all the possible solutions available on the Internet through various articles and different forums, but it didn’t help anyone.

Check out my link and see all the answers if something is useful to you.

How to set the local notification notification interval to a user time interval?

Hope this helps you.

+7
source

The repeatInterval property for UILocalNotification cannot be used to repeat less than each calendar block, that is, every day, every week, every month, etc.

Instead, you will have to schedule several notifications to achieve the desired effect by setting the fireDate property fireDate .

+3
source

Since lemnar says you cannot use repeatInterval to repeat at a frequency other than Apple calendar units. So the code below:

  if([InterValType isEqualToString:@"days"]){ notification.repeatInterval=result*24*60*60; } 

Will do nothing. I also use repeated notifications in the application I created, and the way I got around is to create several notifications, each of which is repeated to give the “desired” frequency of repetition. For example, if I want to repeat "every 2 days", I cannot do this with repeatInterval. However, I have a “scheduling function” in my application that creates several separate notifications to achieve this. I do this by performing an arbitrary period of time (in my case, one week). Therefore, in the above example, when the user indicates that he / she needs a notification every two days from today, I create 3 notifications (one for day 3, 5 and 7).

To repeat at a frequency less than a calendar unit, things are a little easier. Say I need to repeat every 12 hours (at 6am and 6pm). Then I will create 2 notifications (one for 6AM and another for 6PM). Then I set repeatInterval for each of these notifications to NSDayCalendarUnit. So I created a set of notifications that repeat every 12 hours.

When my application loads, I exit after 7 days and update notifications as needed. Not the smartest solution, but it was the best way I could think of getting around the repeatInterval constraint.

+1
source

Source: https://habr.com/ru/post/894609/


All Articles