没有名为 PKPushRegistryDelegate 的类型或协议

No type or protocol named PKPushRegistryDelegate

我正在将 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'

我猜是少了什么东西,但找不到。谁能帮我?

p.s。我正在使用 xcode 9 和 swift 4

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

在您的 AppDelegate 文件中,只需像这样在顶部添加导入:

import PushKit

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