问题描述
我正在尝试使用Firebase来处理推送通知。我安装了 Firebase
pod('Firebase / Core'和'FirebaseMessaging'pods)。
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:
我也遇到与 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及更低版本,因此如果#available(iOS 10.0,*){,则无需添加,只需直接写入其他部分,注册远程通知。
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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!