Capabilities- push notification. Time sensitive notification. Added
below is my method that requests for and sets up notification…
(void)authorizeAndCreateNotificationFromDateComponents:(NSDateComponents *)dateComponents
{
UNUserNotificationCenter *notificationCenter = [UNUserNotificationCenter currentNotificationCenter];
[notificationCenter requestAuthorizationWithOptions:UNAuthorizationOptionAlert|UNAuthorizationOptionBadge|UNAuthorizationOptionSound|UNAuthorizationOptionProvisional completionHandler:^(BOOL granted, NSError *error){
if (granted) {
UNMutableNotificationContent *notificationContent = [[UNMutableNotificationContent alloc] init];
notificationContent.title = @"Add";
notificationContent.body = @"Is it time. Tap to add.";
UNCalendarNotificationTrigger *notificationtrigger = [UNCalendarNotificationTrigger triggerWithDateMatchingComponents:dateComponents repeats:YES];
UNNotificationRequest *notificationRequest = [UNNotificationRequest requestWithIdentifier:@"AddReminder" content:notificationContent trigger:notificationtrigger];
[notificationCenter addNotificationRequest:notificationRequest withCompletionHandler:^(NSError *error){
if (error!=nil) {
NSLog(@"Notification error: %@",error.userInfo);
}
}];
}
}];
}
i call this method from application did finish launching with the following code…
NSDateComponents *hoursAndMinutes = [[NSCalendar currentCalendar] components:NSCalendarUnitHour|NSCalendarUnitMinute fromDate:[NSDate dateWithTimeIntervalSinceNow:20]];
[self authorizeAndCreateNotificationFromDateComponents:hoursAndMinutes];
I am testing this on a device and i dont see any notifications. Although i did see the app in settings.app and immediate, time sensitive and silent (only in notification center without badge or sound) notification have been enabled.
what could be wrong?