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;
        }
Parth Bhatt
  • 19,381
  • 28
  • 133
  • 216
Srinivas
  • 983
  • 9
  • 21

3 Answers3

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.

Community
  • 1
  • 1
Parth Bhatt
  • 19,381
  • 28
  • 133
  • 216
  • Ha.. Now I decided That We Cant Change Custom Repaet Interval. – Srinivas Aug 31 '11 at 13:06
  • it any possible solution Repeat notification Without Using repeat Interval? – Srinivas Sep 01 '11 at 04:04
  • @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 working – Parth Bhatt Sep 01 '11 at 04:14
  • ha.i m thinking .its My requirement In Project to repeat notification.is it possible to store nslocalNotification Object in Db? – Srinivas Sep 01 '11 at 04:19
  • @Srinivas :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. – Parth Bhatt Sep 01 '11 at 04:37
  • 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 Code – Srinivas Sep 03 '11 at 04:14
  • how to repeat notification until User Stop Notification Without Gena rating new Notification. – Srinivas Sep 05 '11 at 04:08
  • @Srinivas: You can only repeat notifications for one day, one week, one month,etc. In short, we can only repeat it for one NSCalendarUnit. – Parth Bhatt Sep 05 '11 at 04:12
  • 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. – Srinivas Sep 05 '11 at 04:18
  • @Srinivas: Yeah I knew that `fireDate` won't be too efficient and hence I didnt suggest you that. – Parth Bhatt Sep 05 '11 at 04:27
  • yeah i face several problems with this...If you find Any Code related To our Scenario please Help me out. – Srinivas Sep 05 '11 at 04:29
  • Sure I Will not publish.please Provide Source Code Asap – Srinivas Sep 07 '11 at 09:05
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.

lemnar
  • 4,063
  • 1
  • 32
  • 44
  • 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 . – Srinivas Aug 31 '11 at 13:03
  • is it possible to NslocalNotification Object In Database.If Possible please Some Guidence – Srinivas Sep 01 '11 at 04:29
  • 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 Code – Srinivas Sep 03 '11 at 04:10
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.

armohan
  • 521
  • 4
  • 12
  • 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... – Srinivas Sep 06 '11 at 04:13