squarefrog
squarefrog

Reputation: 4822

UNUserNotificationCenter always denies authorisation

I'm updating a legacy app to use the UserNotifications framework. After importing UserNotifications in my AppDelegate.swift, I request authorization using the following:

import UserNotifications

///...///

let notificationCenter = UNUserNotificationCenter.current()

notificationCenter.requestAuthorization(options: []) { (granted, error) in
  print("Granted: \(granted), error: \(error)")
  // Enable or disable features based on authorization.
}

However, this always prints the following:

Granted: false, error: Optional(Error Domain=UNErrorDomain Code=1 "Notifications are not allowed for this application" UserInfo={NSLocalizedDescription=Notifications are not allowed for this application})

Am I missing a permission or entitlement somewhere? If I create a new project and add the notification to that, it works fine.

Upvotes: 1

Views: 1151

Answers (1)

squarefrog
squarefrog

Reputation: 4822

I should have caught this sooner, but the issue was due to the project not correctly signing the application.

If you run into this issue, ensure that your Signing Team and Certificate is set.

Upvotes: 2

Related Questions