首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >iOS本地通知不会第二次触发,但会在获取挂起通知请求中显示

iOS本地通知不会第二次触发,但会在获取挂起通知请求中显示
EN

Stack Overflow用户
提问于 2017-05-23 18:57:35
回答 1查看 932关注 0票数 1

我已经实现了iOS 10本地通知,它对第一个警报有效,但对其他警报无效。我导入了iOS 10库,实现了委托,第一次在委托中接收了它,但它后来没有触发。

我的日期格式为: 2017-05-28 14:04:07 +0000

代码语言:javascript
复制
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    [calendar setTimeZone:[NSTimeZone localTimeZone]];
    //(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute)
    NSDateComponents *components = [calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute) fromDate:now];

   NSDate *todaySehri = [calendar dateFromComponents:components];


 UNMutableNotificationContent *objNotificationContent = [[UNMutableNotificationContent alloc] init];

            objNotificationContent.title = [NSString localizedUserNotificationStringForKey:[NSString stringWithFormat:@"Local.."]] arguments:nil];


                  objNotificationContent.body = [NSString localizedUserNotificationStringForKey:@"Incoming Local Notification" arguments:nil];


            objNotificationContent.sound = [UNNotificationSound soundNamed:[NSString stringWithFormat:@"%@",soundFileBtn.titleLabel.text]]; // [UNNotificationSound defaultSound];//soundFileBtn.titleLabel.text;// [UNNotificationSound defaultSound];
            NSDictionary *dict = @{@"alarmID":self.myKey,
                                                   @"SOUND_TYPE":[NSString stringWithFormat:@"%li",(long)self.audio_segment.selectedSegmentIndex]
                                                   };
            NSArray *array = [NSArray arrayWithObjects:dict, nil];
            NSDictionary *data = [NSDictionary dictionaryWithObject:array forKey:@"payload"];


            [objNotificationContent setUserInfo:data];

            //update application icon badge number
            objNotificationContent.badge = @([[UIApplication sharedApplication] applicationIconBadgeNumber] + 0);

            NSCalendar *cal = [NSCalendar currentCalendar];

              NSDateComponents *compss= [cal components:(NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute)
                          fromDate:todaySehri];

             UNCalendarNotificationTrigger *trigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:compss repeats:NO];

            UNNotificationRequest *request = [UNNotificationRequest requestWithIdentifier:[todaySehri description]
                                                                                  content:objNotificationContent trigger:trigger];
            //schedule localNotification
            UNUserNotificationCenter *center = [UNUserNotificationCenter currentNotificationCenter];
            [center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
                if (!error) {
                    NSLog(@"Local Notification succeeded");
                }
                else {
                    NSLog(@"Local Notification failed");
                }
            }];
EN

回答 1

Stack Overflow用户

发布于 2017-05-24 13:05:36

如何将触发器YES设置为repeat?另外,看看这个。repeating local notifications的答案

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44132879

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档