How To set Custom repeat interval For Nslocal Notification…?

房东的猫 提交于 2019-12-22 05:10:42

问题


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

回答1:


@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.




回答2:


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.




回答3:


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.



来源:https://stackoverflow.com/questions/6991771/how-to-set-custom-repeat-interval-for-nslocal-notification

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!