【发布时间】:2019-07-29 08:29:06
【问题描述】:
我正在更新旧版应用程序以使用 UserNotifications 框架。在我的AppDelegate.swift 中导入UserNotifications 后,我使用以下命令请求授权:
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})
我是否在某处遗漏了许可或权利?如果我创建一个新项目并向其中添加通知,它就可以正常工作。
【问题讨论】:
-
对我来说,原因是不同的。在这里回答:stackoverflow.com/a/66108609/2348614
标签: macos unusernotificationcenter