我正在更新一个遗留应用程序以使用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})我是否遗漏了某个权限或权利?如果我创建一个新项目并向其中添加通知,它将正常工作。
发布于 2019-03-07 22:38:13
我应该早点发现这个问题,但这个问题是由于项目没有正确地签署应用程序造成的。
如果遇到此问题,请确保设置了签名团队和证书。
https://stackoverflow.com/questions/55044027
复制相似问题