UNUserNotificationCenter始终拒绝授权

时间:2019-03-07 12:38:57

标签: macos unusernotificationcenter

我正在更新旧版应用程序以使用UserNotifications框架。在将UserNotifications导入AppDelegate.swift后,我使用以下命令请求授权:

import UserNotifications

///...///

let notificationCenter = UNUserNotificationCenter.current()

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

但是,这始终会打印以下内容:

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})

我在某处缺少许可或权利吗?如果我创建一个新项目并向其中添加通知,那么它将正常工作。

1 个答案:

答案 0 :(得分:0)

本来应该早点发现的,但是问题出在项目没有正确签名应用程序。

如果遇到此问题,请确保已设置签名团队和证书。

相关问题