目前我正在使用 Xcode 7.2
我有这样的要求:实际上我想在上午 8:00 和晚上 8:00 安排每日通知(每天仅两次)。
我不熟悉本地通知的使用。我做了一些研发我发现一些链接也喜欢:Daily UILocalNotification firing more than once .但我无法解决我的问题....
如果应用程序处于非事件/事件/后台/暂停,我需要向特定用户显示本地通知。
我该如何克服这个问题?
早上 8:00 的通知
UILocalNotification *localNotif1 = [[UILocalNotification alloc] init];
localNotif1.alertBody = @"Morning 8:00 AM";
NSDateComponents *components1 = [[NSCalendar currentCalendar] componentsNSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitWeekOfMonth) fromDate:[NSDate date]];
[components1 setHour:8];
[components1 setMinute:0];
localNotif1.fireDate = [[NSCalendar currentCalendar] dateFromComponents:components1];
[localNotif1 setRepeatInterval:NSCalendarUnitDay];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif1];
晚上 8:00 的通知
UILocalNotification *localNotif2 = [[UILocalNotification alloc] init];
localNotif2.alertBody = @"Evening 8:00 PM";
NSDateComponents *components2 = [[NSCalendar currentCalendar] componentsNSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitWeekOfMonth) fromDate:[NSDate date]];
[components2 setHour:20];
[components2 setMinute:0];
localNotif2.fireDate = [[NSCalendar currentCalendar] dateFromComponents:components2];
[localNotif2 setRepeatInterval:NSCalendarUnitDay];
[[UIApplication sharedApplication] scheduleLocalNotification:localNotif2];
关于ios - 如何设置本地通知在(早上 8 :00AM and Evening 8:00PM) in ios?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36128366/
欢迎光临 OStack程序员社区-中国程序员成长平台 (https://ostack.cn/) | Powered by Discuz! X3.4 |