iOS local notification not firing second time but shows in getpendingnotificationrequests

有些话、适合烂在心里 提交于 2019-11-28 12:08:26

问题


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.

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

回答1:


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



来源:https://stackoverflow.com/questions/44132879/ios-local-notification-not-firing-second-time-but-shows-in-getpendingnotificatio

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!