iOS本地通知不会第二次触发,但会在getpendingnotification请求中显示 [英] iOS local notification not firing second time but shows in getpendingnotificationrequests

查看:353
本文介绍了iOS本地通知不会第二次触发,但会在getpendingnotification请求中显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经实现了iOS 10本地通知,该通知在第一个警报中有效,而在其他警报中则无效.我已经导入了iOS 10库,实现了委托,第一次在委托中接收它,但是稍后不再触发.

I have implemented iOS 10 local notification where it works for the first alarm but not for other. I have import iOS 10 library , implemented delegate , receiving it first time in the delegate but it just not firing later.

我的约会伙伴看起来像:2017-05-28 14:04:07 +0000

My date formate looks like : 2017-05-28 14:04:07 +0000

    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");
                }
            }];

推荐答案

如何将触发器YES设置为重复执行?另外,请检查一下. 重复本地通知的答案

How about setting your trigger YES to repeat? Also, check this out. answer for repeating local notifications

这篇关于iOS本地通知不会第二次触发,但会在getpendingnotification请求中显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆