【问题标题】:UNUserNotificationCenter always denies authorisationUNUserNotificationCenter 总是拒绝授权
【发布时间】: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})

我是否在某处遗漏了许可或权利?如果我创建一个新项目并向其中添加通知,它就可以正常工作。

【问题讨论】:

标签: macos unusernotificationcenter


【解决方案1】:

我应该早点发现这个问题,但问题是由于项目没有正确签署应用程序。

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-03
    • 1970-01-01
    • 2011-04-21
    • 2015-05-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多