【问题标题】:Not able to import UserNotifications in iOS Swift无法在 iOS Swift 中导入 UserNotifications
【发布时间】:2017-02-27 16:29:09
【问题描述】:

我正在尝试使用 Firebase 实现推送通知。我已经使用 cocapod 安装了“Firebase/Core”和“Firebase/Messaging”框架。 我可以在文件中导入 FirebaseInstanceID 和 FirebaseMessaging。但是对于 “import UserNotifications”,它会显示 “No such Module”。我正在使用 Swift 2.1.1Xcode 7.3.1,我的目标 iOS 是 8.1+ ... 请帮助,在此先感谢。

【问题讨论】:

  • 此类在Xcode 7.3.1 中不可用。使用xcode 8
  • UserNotifications 仅适用于 iOS 10+ -- 你需要 Xcode 8

标签: ios iphone swift firebase usernotifications


【解决方案1】:

升级到 XCode 8 可能是最好的选择。

但如果您由于某种原因不能或不想升级,您可以使用旧的 APN 注册方式(无需导入 UserNotifications):

    let settings: UIUserNotificationSettings =
        UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
    application.registerUserNotificationSettings(settings)
    application.registerForRemoteNotifications()

Firebase Messaging 可以使用,但一些新的 iOS10 功能可能无法使用。

【讨论】:

    【解决方案2】:

    UserNotification 适用于 iOS 10 及更高版本。 Xcode 7.3.1 仅支持 iOS 9。 如果你需要使用这个框架。您需要更新到支持 iOS 10 的最新 Xcode(显然是 Xcode8)。

    【讨论】:

      猜你喜欢
      • 2014-07-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-31
      • 2016-11-21
      • 1970-01-01
      相关资源
      最近更新 更多