HTML5   发布时间:2022-04-27  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了iOS在特定日期设置本地通知大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我确信这个问题在某个地方是重复的,但我找不到解决办法.我正在创建一个应用程序,其中一个功能允许用户选择他们将收到本地通知的日期和时间.

他们可以选择他们喜欢的一天中的任何时间,并可以切换一周中的不同日期(周一,周二,妻子等).通知将每周发送一次.因此,我限制用户只创建3个通知 – 如果选择了所有7天,我会将repeaTinterval设置为daily(一个通知).如果为每3个通知选择了6天,那么我将需要每天的单独通知(总共3×6 = 18个通知).很可能只会使用1个通知,所以这很好.

我知道如何在将来的某个时间设置通知,但如何在星期一下午6点设置通知

下面是我用于测试的代码.它将来会设置4秒的警报(我从applicationDidEnterBACkground调用它).

NSDateComponents *changeComponent = [[NSDateComponents alloc] init];
    changeComponent.second = 4;

    NSCalendar *theCalendar = [NSCalendar currentCalendar];
    NSDate *itemDate = [theCalendar dateByAddingComponents:changeComponent toDate:[NSDate date] options:0];

    UIlocalnotification *localNotif = [[UIlocalnotification alloc] init];
    localNotif.fireDate = itemDate;
    localNotif.timeZone = [NSTimeZone defaultTimeZone];
    localNotif.repeaTinterval = NSWeekdayCalendarUnit;

解决方法

与您现在正在做的完全相同,但以不同方式创建日期:

NSDateComponents *comps = [[[NSDateComponents alloc] init] autorelease];
[comps setDay:1];
[comps setMonth:1];
[comps setYear:2013];
[comps setHour:10];
[comps setminute:10];
[comps setSecond:10];
localNotif.fireDate = [[NSCalendar currentCalendar] dateFromComponents:comps];

大佬总结

以上是大佬教程为你收集整理的iOS在特定日期设置本地通知全部内容,希望文章能够帮你解决iOS在特定日期设置本地通知所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。