How To set Custom repeat interval For Nslocal Notification.....?
Asked Answered
T

3

6

i am New to iphone Development .I Am Trying To Use NslocalNotification In My Project I Need To Give Remeinder For Every 2Hours or For Every Two Days Or For Every Two Months Etc..Currently I am Using NslocalNotification Repeat Interval .But Its Working For Only 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 result is 2 depend Up on IntervalType I Need Notification its Not Working With Me

         if([InterValType isEqualToString:@"days"]){
             notification.repeatInterval=result*24*60*60;
        }
Tsarevitch answered 9/8, 2011 at 5:32 Comment(1)
Was my answer helpful to you?Mccreery
M
7

@Srinivas:

If you look at the link I have posted in this answer, You will come to know that I have tried every possible solution here to try and do what you want currently.

I had tried all this to implement it in my app, but this doesn't work.

I am afraid to say this but this is not possible. It only allows the unit NSCalendarUnit objects to be set as a repeat interval.

I invested almost 2 months (I asked the question in Dec 2010 and answered it myself in February 2011) to try and implement every possible solution available on internet through different articles and different forums but none did help.

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

How to set Local Notification repeat interval to custom time interval?

Really Hope that this helps you.

Mccreery answered 31/8, 2011 at 12:13 Comment(12)
Ha.. Now I decided That We Cant Change Custom Repaet Interval.Tsarevitch
it any possible solution Repeat notification Without Using repeat Interval?Tsarevitch
@Srinivas: Seriously speaking I don't think that we can do it by any means as the notification.repeatInterval has the receiever type as NSCalendarUnit I don't think that it is possible to tweek it in some way to get custom intervals workingMccreery
ha.i m thinking .its My requirement In Project to repeat notification.is it possible to store nslocalNotification Object in Db?Tsarevitch
@Tsarevitch :I am not about that but may be you can try with blob datatype. But honestly speaking I have never tried that and neither I know much about it. Hope this helps.Mccreery
ha your absolute right but is there any way to repeat interval.with storing notification object in database.please Help me out.if possible Give any Sample CodeTsarevitch
how to repeat notification until User Stop Notification Without Gena rating new Notification.Tsarevitch
@Srinivas: You can only repeat notifications for one day, one week, one month,etc. In short, we can only repeat it for one NSCalendarUnit.Mccreery
ha...its possible but In This Project They Want For Every 25 min Notification .i am trying With One case When ever we Got Notification in app delegate Did receive notification method set To NextFireDate but Is Not Working Great.Tsarevitch
@Srinivas: Yeah I knew that fireDate won't be too efficient and hence I didnt suggest you that.Mccreery
yeah i face several problems with this...If you find Any Code related To our Scenario please Help me out.Tsarevitch
Sure I Will not publish.please Provide Source Code AsapTsarevitch
S
3

The repeatInterval property of a UILocalNotification cannot be used to repeat less than every one calendar unit, i.e. every day, every week, every month, etc.

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

Seringa answered 31/8, 2011 at 12:52 Comment(3)
its a Medicine Application We Have Several schedules For Same Medicine Name.so How Can I Set Every Time Fire Date. Its Working Perfect For Every Day Month Minute,Hour .Tsarevitch
is it possible to NslocalNotification Object In Database.If Possible please Some GuidenceTsarevitch
ha your absolute right but is there any way to repeat interval.with storing notification object in database.please Help me out.if possible Give any Sample CodeTsarevitch
R
1

As lemnar says you are unable to use repeatInterval to repeat in a frequency different from the calendar units Apple provided. So, the code below:

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

Will not do anything. I am also using repeat notifications in an app that I have built and the way I've gotten around this is by creating multiple notifications each repeating to give the "desired" repeat frequency. As an example, if I want to repeat "every 2 days", I can't do this using repeatInterval. However, I have a "scheduling function" in my app that creates multiple individual notifications to achieve this. I do this going out an arbitrary length of time (in my case, one week). So in the example above, when the user specifies that he / she needs a notification every two days from today, I create 3 notifications (one each for day 3, 5, and 7).

For repeating 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 would create 2 notifications (one for 6AM and another for 6PM). I would then set the repeatInterval for each of these notifications to NSDayCalendarUnit. This way I have created a set of notifications that repeat every 12 hours.

When my app loads, I go out another 7 days and recreate notifications as needed. Not the most elegant solution, but this was the best way I could think of getting around the repeatInterval limitation.

Renfro answered 5/9, 2011 at 19:31 Comment(1)
thanks For Your Great Answer.....As You Told When my app loads, I go out another 7 days and recreate notifications as needed.when receive notification or when ever app became active...Tsarevitch

© 2022 - 2024 — McMap. All rights reserved.