Firebase Cloud Messaging AppDelegateエラー

ジュヌウ:

これは、Firebaseドキュメントのコードです。

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は「宣言されていないタイプの使用言いUNAuthorizationOptionsUNUserNotificationCenterFIRMessagingDelegate

そしてもう一行あります。

NotificationCenter.defaultCenter.addObserver(self,selector: #selector(self.tokenRefreshNotification),name: kFIRInstanceIDTokenRefreshNotification,object: nil)

「タイプAppDelegateの値にはメンバーがありませんtokenRefreshNotification」と表示されます

firebase docsからコードをコピーして貼り付けましたが、エラーが発生しました!

アレクセイ:

Firebaseドキュメントの例は古くなっています。最新のXcode 9とSwift 3のコードは次のとおりです。

import Firebase
import UserNotifications

class AppDelegate: UIResponder, UIApplicationDelegate {


    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {


        FIRApp.configure()

        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)
             Messaging.messaging().delegate = self                
        }

        application.registerForRemoteNotifications()

        return true
    }
}


@available(iOS 10, *)
extension AppDelegate : UNUserNotificationCenterDelegate {

    // Receive displayed notifications for iOS 10 devices.

    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        let userInfo = notification.request.content.userInfo
        // Print message ID.
        print("Message ID: \(userInfo["gcm.message_id"]!)")

        // Print full message.
        print("%@", userInfo)

    }

}

extension AppDelegate : MessagingDelegate {
// Receive data message on iOS 10 devices.
func applicationReceivedRemoteMessage(_ remoteMessage: MessagingRemoteMessage) {
    print("%@", remoteMessage.appData)
    }
}

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

Firebase Cloud Messaging 通知キー名

分類Dev

Firebase Cloud Messaging Statistics API

分類Dev

Notification from Firebase cloud messaging are received but they are not shown in the cloud messaging reports

分類Dev

Firebase Cloud Messaging - Error calling firebase.messaging()

分類Dev

AppDelegateを使用しないSwiftUIリモートプッシュ通知(Firebase Cloud Messaging)

分類Dev

Firebase Cloud Messaging - Managing Registration Tokens

分類Dev

Firebase Cloud Messaging notification not received on iOS

分類Dev

Firebase Cloud MessagingはonDeletedMessages()をオーバーライドします

分類Dev

Firebase Cloud Messaging - Target to single device not visible in Firebase console

分類Dev

Firebase Cloud Messaging: Device Group sending support in Firebase Admin SDK

分類Dev

Firebase Cloud Messagingにはサーバーが必要ですか?

分類Dev

Firebase Cloud MessagingのAPIキーはどこにありますか?

分類Dev

Firebase Cloud Messaging-登録トークンの管理

分類Dev

Firebase Cloud Messagingはパッケージ名に依存しますか?

分類Dev

Firebase Cloud Messaging: App Server でのトークン更新の処理

分類Dev

Firebase Cloud Messagingの使用中は、メッセージをRemoteMessageエラーに変換できません

分類Dev

エラー:「データには文字列値のみを含める必要があります」Firebase Cloud Messaging

分類Dev

Does Firebase Cloud Messaging support VOIP pushkit services?

分類Dev

Firebase Cloud Messagingは無料ですか?

分類Dev

Firebase Cloud Messagingは無料ですか?

分類Dev

How to auto increment iOS notification badge with Firebase Cloud Messaging?

分類Dev

How to migrate Azure Notification hub to Firebase Cloud Messaging?

分類Dev

Firebase Cloud Messaging認証は必要ですか?

分類Dev

Firebase Cloud Messaging SystemUIが停止しました

分類Dev

Firebase send http cloud messaging from android app

分類Dev

Is it possible to use Firebase Cloud Messaging API to list all push notifications?

分類Dev

Firebase Cloud Messaging in flutter function works but didn't receive notification

分類Dev

JSON を Firebase Cloud Messaging に送信する

分類Dev

Firebase Cloud Messagingのアプリサーバーはいつ必要ですか?

Related 関連記事

  1. 1

    Firebase Cloud Messaging 通知キー名

  2. 2

    Firebase Cloud Messaging Statistics API

  3. 3

    Notification from Firebase cloud messaging are received but they are not shown in the cloud messaging reports

  4. 4

    Firebase Cloud Messaging - Error calling firebase.messaging()

  5. 5

    AppDelegateを使用しないSwiftUIリモートプッシュ通知(Firebase Cloud Messaging)

  6. 6

    Firebase Cloud Messaging - Managing Registration Tokens

  7. 7

    Firebase Cloud Messaging notification not received on iOS

  8. 8

    Firebase Cloud MessagingはonDeletedMessages()をオーバーライドします

  9. 9

    Firebase Cloud Messaging - Target to single device not visible in Firebase console

  10. 10

    Firebase Cloud Messaging: Device Group sending support in Firebase Admin SDK

  11. 11

    Firebase Cloud Messagingにはサーバーが必要ですか?

  12. 12

    Firebase Cloud MessagingのAPIキーはどこにありますか?

  13. 13

    Firebase Cloud Messaging-登録トークンの管理

  14. 14

    Firebase Cloud Messagingはパッケージ名に依存しますか?

  15. 15

    Firebase Cloud Messaging: App Server でのトークン更新の処理

  16. 16

    Firebase Cloud Messagingの使用中は、メッセージをRemoteMessageエラーに変換できません

  17. 17

    エラー:「データには文字列値のみを含める必要があります」Firebase Cloud Messaging

  18. 18

    Does Firebase Cloud Messaging support VOIP pushkit services?

  19. 19

    Firebase Cloud Messagingは無料ですか?

  20. 20

    Firebase Cloud Messagingは無料ですか?

  21. 21

    How to auto increment iOS notification badge with Firebase Cloud Messaging?

  22. 22

    How to migrate Azure Notification hub to Firebase Cloud Messaging?

  23. 23

    Firebase Cloud Messaging認証は必要ですか?

  24. 24

    Firebase Cloud Messaging SystemUIが停止しました

  25. 25

    Firebase send http cloud messaging from android app

  26. 26

    Is it possible to use Firebase Cloud Messaging API to list all push notifications?

  27. 27

    Firebase Cloud Messaging in flutter function works but didn't receive notification

  28. 28

    JSON を Firebase Cloud Messaging に送信する

  29. 29

    Firebase Cloud Messagingのアプリサーバーはいつ必要ですか?

ホットタグ

アーカイブ