【问题标题】:No type or protocol named PKPushRegistryDelegate没有名为 PKPushRegistryDelegate 的类型或协议
【发布时间】:2018-01-19 08:44:25
【问题描述】:

我正在向我的应用程序添加 PushKit 通知,并偶然发现了上述错误。

我做了什么:

  1. 启用推送通知
  2. 在后台模式下启用远程通知
  3. 添加了链接框架 PushKit.framework

我用 PKPushRegistryDelegate 扩展了我的 AppDelegate 并实现了 pushRegistry 方法:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, PKPushRegistryDelegate {
func pushRegistry(_ registry: PKPushRegistry, didUpdate pushCredentials: PKPushCredentials, forType type: PKPushType) {

}
.
.
.

一切似乎都很好,但是当我构建时出现错误:

No type or protocol named PKPushRegistryDelegate

在这种情况下我也尝试了扩展,但我得到了一个不同的错误:

Cannot find protocol declaration for 'PKPushRegistryDelegate'

我猜测缺少某些东西,但找不到什么。谁能帮我?

附言我正在使用 xcode 9 和 swift 4

【问题讨论】:

  • 您是否在文件中导入了 PushKit ?
  • 我做到了。问题是缺少 Bridging-Header.h 中的导入。它现在可以工作了:)

标签: ios push-notification delegates swift-protocols pushkit


【解决方案1】:

在 Bridging-Header.h 中导入#import,现在可以使用了。

【讨论】:

    【解决方案2】:

    在您的 AppDelegate 文件中,只需在顶部添加导入,如下所示:

    import PushKit

    无需在 Bridging-Header 中添加任何内容。

    【讨论】:

      猜你喜欢
      • 2016-04-08
      • 2016-11-05
      • 2020-12-30
      • 2022-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多