Connection error sending Local UserNotification

I am getting this error when I actually try to send a local notification, even when the app has been given proper access:

Error sending notification: Error Domain=NSCocoaErrorDomain Code=4097 "connection to service with pid 586 named com.apple.usernotifications.usernotificationservice"

Here is the notification sending code, though it is pretty straight forward:

		UNMutableNotificationContent * userNote = [UNMutableNotificationContent new];
		NSMutableArray * identifiers = [NSMutableArray new];
		if (messages.count == 1) {
			userNote.title = messages[0].sender[0].displayName;
			userNote.subtitle = messages[0].subject;
		}
		else {
			NSString * mkApplicationName = NSBundle.mainBundle.infoDictionary[@"CFBundleName"];
			userNote.title = MKStringWithLocalizedFormat(@"@APP_RECEIVED_@NUM_MESSAGES", mkApplicationName, messages.count);
		}

		for (MKMessage* message in messages) {
			if (message.postmarkIdentifier) {
				[identifiers addObject:message.postmarkIdentifier];
			}
		}

		userNote.body = self.notificationMessage;
		userNote.userInfo = @{@"MessageIdentifiers":identifiers};

		// Deliver the notification in now
		UNTimeIntervalNotificationTrigger * trigger = [UNTimeIntervalNotificationTrigger
													   triggerWithTimeInterval:0.1 repeats:NO];
		UNNotificationRequest * request = [UNNotificationRequest requestWithIdentifier:@"RuleNotification"
																			   content:userNote trigger:trigger];

		// Schedule the notification.
		UNUserNotificationCenter * center = [UNUserNotificationCenter currentNotificationCenter];
		[center addNotificationRequest:request withCompletionHandler:^(NSError * _Nullable error) {
			if (error) {
				NSLog(@"Error sending notification: %@", error);
			}
		}];

Any ideas would be helpful, thanks,

Scott

Post not yet marked as solved Up vote post of lksoft Down vote post of lksoft
676 views
  • I've been randomly getting this too in iOS 15.4-6 but can't pin point when. Have you figured anything about this?

Add a Comment

Replies

Just to be clear, when I get the notificationSettings, it says that the authorizationStatus is authorized!