這是Firebase文檔中的代碼。Firebase Cloud Messaging AppDelegate錯誤
if #available(iOS 10.0, *) {
let authOptions : UNAuthorizationOptions = [.Alert, .Badge, .Sound]
UNUserNotificationCenter.currentNotificationCenter().requestAuthorizationWithOptions(
authOptions,
completionHandler: {_,_ in })
// For iOS 10 display notification (sent via APNS)
UNUserNotificationCenter.currentNotificationCenter().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)
}
我沒有修改任何代碼行。但Xcode說:「使用未申報類型UNAuthorizationOptions
,UNUserNotificationCenter
,FIRMessagingDelegate
」
我還有一行。
NotificationCenter.defaultCenter.addObserver(self,selector: #selector(self.tokenRefreshNotification),name: kFIRInstanceIDTokenRefreshNotification,object: nil)
它說「類型的AppDelegate的價值沒有成員tokenRefreshNotification
」
我只是複製和火力文檔粘貼我的代碼,但有錯誤!
所以,我必須使用Xcode的8?當我在Xcode 7.3.1中導入UserNotifications時,出現錯誤:沒有這樣的模塊'UserNotifications'... –
是的,這段代碼是用於Xcode8的 – Alexey
請問您是否更新objective-c? – Nik