Ios Firebase通知Swift 3

Ios Firebase通知Swift 3,ios,swift,firebase,firebase-cloud-messaging,Ios,Swift,Firebase,Firebase Cloud Messaging,我的主要错误是: #选择器的参数引用了未向Objective-C公开的实例方法“tokenRefreshNotification” 这是我的AppDelegate: @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? let gcmMessageIDKey = "gcm.message_id" func application(

我的主要错误是:

#选择器的参数引用了未向Objective-C公开的实例方法“tokenRefreshNotification”

这是我的AppDelegate:

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    let gcmMessageIDKey = "gcm.message_id"

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

        GMSServices.provideAPIKey("appKey")

        FIRApp.configure()

        //Firebase
        if #available(iOS 10.0, *) {
            // For iOS 10 display notification (sent via APNS)
            UNUserNotificationCenter.current().delegate = self

            let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
            UNUserNotificationCenter.current().requestAuthorization(options: authOptions,
                                                                    completionHandler: {_, _ in})

            // For iOS 10 data message (sent via FCM)
            FIRMessaging.messaging().remoteMessageDelegate = self
        } else {
            let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [ .alert, .badge, .sound], categories: nil)
            application.registerUserNotificationSettings(settings)
        }

        application.registerForRemoteNotifications()


        // Add observer for iNSTANCEid TOKEN REFRESH CALLBACK.
        NotificationCenter.default.addObserver(self, selector: #selector(self.tokenRefreshNotification), name: .firInstanceIDTokenRefresh, object: nil)

        // Override point for customization after application launch.
        return FBSDKApplicationDelegate.sharedInstance().application(application, didFinishLaunchingWithOptions: launchOptions)
    }
    // [START refresh_token]
    func tokenRefreshNotification(_ notification: Notification)
    {
        if let refreshedToken = FIRInstanceID.instanceID().token() {
            print("InstanceID Token \(refreshedToken)")
        }

        // Connect to FCM since connection may have failed when attempted before having a token
        connectToFCM()
    }
    // [END refresh_token]

    // [START connect_to_fcm]
    func connectToFCM()
    {
        // Won't connect since there is no token
        guard FIRInstanceID.instanceID().token() != nil else {
            return
        }

        // Disconnect previous FCM connection if it exists
        FIRMessaging.messaging().disconnect()

        FIRMessaging.messaging().connect(completion: {(error) in
            if error != nil {
                print("Unable to connect with FCM \(error)")
            } else {
                print("Connected to FCM")
            }
        })

    }
    // [END connect_to_fcm]
错误行如下所示:

NotificationCenter.default.addObserver(self, selector: #selector(self.tokenRefreshNotification), name: .firInstanceIDTokenRefresh, object: nil)
如果我将@objc添加到tokenRefreshNotification,我会收到一个新错误:

“方法不能是marker@objc因为参数的类型不能在目标C中表示”


选择器错误,应重新设置

NotificationCenter.default.addObserver(self, selector: #selector(tokenRefreshNotification:), name: .firInstanceIDTokenRefresh, object: nil)
@objc func tokenRefreshNotification(notification: Notification) {
选择器的末尾必须有“:”

此外,方法签名似乎是错误的,应该

NotificationCenter.default.addObserver(self, selector: #selector(tokenRefreshNotification:), name: .firInstanceIDTokenRefresh, object: nil)
@objc func tokenRefreshNotification(notification: Notification) {

下划线太多。

我也遇到了这个错误-您修复了吗?我也遇到了这个问题。你找到解决办法了吗?这并不能解决问题