如何为 Nslocal 通知设置自定义重复间隔......?

发布于 2024-11-28 20:52:25 字数 1129 浏览 5 评论 0原文

我是 iphone 开发新手。我正在尝试在我的项目中使用 NslocalNotification 我需要每 2 小时或每两天或每两个月等给出提醒。目前我正在使用 NslocalNotification 重复间隔。但它仅适用于使用 Ncalender 每小时每分钟 ....

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

此处如果结果为 2 取决于 IntervalType 我需要通知 它不适合我

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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

懵少女 2024-12-05 20:52:25

@Srinivas:

如果您查看我在这个答案中发布的链接,您会知道我已经尝试了这里所有可能的解决方案来尝试做您目前想做的事情。

我已经尝试了所有这些来在我的应用程序中实现它,但这不起作用。

我不敢这么说,但这是不可能的。它只允许将 unit NSCalendarUnit 对象设置为重复间隔。

我花了近 2 个月的时间(我在 2010 年 12 月提出了这个问题,并在 2011 年 2 月自己回答了这个问题),通过不同的文章和不同的论坛尝试实施互联网上提供的所有可能的解决方案,但没有一个有帮助。

如果某些内容对您有用,请查看我的链接并查找所有答案。

如何将本地通知重复间隔设置为自定义时间间隔?

真的希望这对您有帮助。

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

陪我终i 2024-12-05 20:52:25

UILocalNotificationrepeatInterval 属性不能用于少于每个日历单位的重复,即每天、每周、每月等。

相反,您必须安排多个通知以达到所需的效果,并相应地设置 fireDate 属性。

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.

破晓 2024-12-05 20:52:25

正如 lemnar 所说,您无法使用 RepeatInterval 以与 Apple 提供的日历单位不同的频率进行重复。所以,下面的代码:

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

不会做任何事情。我还在我构建的应用程序中使用重复通知,我解决这个问题的方法是创建多个通知,每个通知重复给出“所需的”重复频率。举个例子,如果我想“每 2 天”重复一次,我不能使用 RepeatInterval 来做到这一点。但是,我的应用程序中有一个“调度功能”,可以创建多个单独的通知来实现此目的。我这样做的时间是任意长的(在我的例子中是一周)。因此,在上面的示例中,当用户指定他/她需要从今天起每两天收到一次通知时,我创建 3 个通知(第 3、5 和 7 天各一个)。

对于以小于日历单位的频率重复,事情要容易一些。假设我需要每 12 小时重复一次(早上 6 点和下午 6 点)。然后,我会创建 2 个通知(一个用于上午 6 点,另一个用于下午 6 点)。然后,我将每个通知的重复间隔设置为 NSDayCalendarUnit。通过这种方式,我创建了一组每 12 小时重复一次的通知。

当我的应用程序加载时,我会再出去 7 天并根据需要重新创建通知。这不是最优雅的解决方案,但这是我能想到的绕过重复间隔限制的最佳方法。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文