问题描述
我正在尝试使用 Firebase 来处理推送通知.我已经安装了 Firebase
pod(Firebase/Core"和FirebaseMessaging"pod).
I am trying to use Firebase to handle push notifications. I have installed Firebase
pod ('Firebase/Core' and 'FirebaseMessaging' pods).
在我将 Firebase 导入项目之后
And after I imported Firebase to the project
import Firebase
我已经像这样配置了 Firebase 应用(代码是从官方文档中复制的):
I have configured the Firebase app like this( code is copied from official docs ):
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?)
-> Bool {FIRApp.configure() }
之后我尝试使用此代码(代码是从官方文档中复制的):
After that I've tried to use this code ( code is copied from official docs ):
if #available(iOS 10.0, *) {
let authOptions : UNAuthorizationOptions = [.alert, .badge, .sound]
UNUserNotificationCenter.current().requestAuthorization(
options: authOptions,
completionHandler: {_,_ in })
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.current().delegate = self
// For iOS 10 data message (sent via FCM)
FIRMessaging.messaging().remoteMessageDelegate = self
} else {
let settings: UIUserNotificationSettings =
UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(settings)
}
application.registerForRemoteNotifications()
但是我从标题中得到了错误:
But I got the error from the title which says:
使用未声明的类型 UNAuthorizationOptions
我也有与 UNUserNotificationCenter
类相关的相同错误.
also I am having the same error related to the UNUserNotificationCenter
class.
我使用的是 Swift 2.2 和 Xcode 7.3.1
I am using Swift 2.2 and Xcode 7.3.1
这个错误的原因是什么?
What is the cause of this error?
推荐答案
UserNotifications.framework
可从 iOS 10 获得,您使用 Xcode 7.3 意味着使用 iOS 9 及更低版本,因此没有需要你添加if #available(iOS 10.0, *) {
,直接只写else部分并注册远程通知.
UserNotifications.framework
is available from iOS 10 and you are working with Xcode 7.3 means with iOS 9 and lower, So there is no need for you to add that if #available(iOS 10.0, *) {
, write only else part directly and register remote notifications.
let settings: UIUserNotificationSettings = UIUserNotificationSettings(forTypes: [.Alert, .Badge, .Sound], categories: nil)
application.registerUserNotificationSettings(settings)
application.registerForRemoteNotifications()
这篇关于使用未声明的类型 UNAuthorizationOptions的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!