Использование неразрешенного идентификатора 'InstanceIDAPNSTokenType' - PullRequest
0 голосов
/ 04 октября 2018

Проблема с неразрешенным идентификатором была решена ранее, и я выполнил все шаги от репозитория до установки (удаления firebase из pod) и переустановки с помощью firebase in pod ... и т. Д., И все же это не решило эту проблему.Эта проблема вместе с другими возникла, когда я обновил модуль.Эта проблема возникает с функцией в AppDelegate.

Вот мой AppDelegate.swift

import UIKit
import Firebase
import FirebaseMessaging
import FirebaseAuth
import FirebaseDatabase
import UserNotifications

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, MessagingDelegate, 
UNUserNotificationCenterDelegate {

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    // Override point for customization after application launch.

    FirebaseApp.configure()

    // Messaging Delegate
    Messaging.messaging().delegate = self

    // Notification delegate
    UNUserNotificationCenter.current().delegate = self

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

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

    } else {
        let settings: UIUserNotificationSettings =
            UIUserNotificationSettings(types: [.alert, .badge, .sound], categories: nil)
        application.registerUserNotificationSettings(settings)
    }

    application.registerForRemoteNotifications()

    return true
}

func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {

    print("Registered with FCM with token:", fcmToken)
    [Messaging.messaging().fcmToken!:Messaging.messaging().fcmToken as AnyObject]
}

//
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {

    InstanceID.instanceID().setAPNSToken(deviceToken, type: InstanceIDAPNSTokenType.sandbox)
}

// Listen for user notifications - basically show the notification while a user is on foreground mode
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
    completionHandler(.alert)

    // Reset badge number to zero
    if let userID = Auth.auth().currentUser?.uid {

        let dbRef = Database.database().reference()
        dbRef.child("Users Info").child(userID).updateChildValues(["badge":"0"], withCompletionBlock: { (err, ref) in
            if err != nil {
                print(err!)
                return
            }
        })

    }


}

func userNotificationCenter(_ center: UNUserNotificationCenter, didReceive response: UNNotificationResponse, withCompletionHandler completionHandler: @escaping () -> Void) {


    if let mainTabBarController = window?.rootViewController as? MainTabBarControllerViewController {

        mainTabBarController.selectedIndex = 1

        mainTabBarController.tabBar.items?[1].badgeValue = nil


    }

}

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
    completionHandler(.newData)

    if let aps = userInfo["aps"] as? [String:Any] {
        let badgeNumber = aps["badge"] as! Int

        if let mainTabBarController = window?.rootViewController as? MainTabBarControllerViewController {

            mainTabBarController.tabBar.items?[1].badgeValue = String(Int(badgeNumber))

        }

    }

}



func applicationWillResignActive(_ application: UIApplication) {

}

func applicationDidEnterBackground(_ application: UIApplication) {


}

func applicationWillEnterForeground(_ application: UIApplication) {

}

func applicationDidBecomeActive(_ application: UIApplication) {

    if let mainTabBarController = window?.rootViewController as? MainTabBarControllerViewController {

        if  mainTabBarController.selectedIndex == 1 {

            // Reset Requests tab's badge
            mainTabBarController.tabBar.items?[1].badgeValue = nil
        }

    }


    application.applicationIconBadgeNumber = 0

    // Reset badge number to zero
    if let userID = Auth.auth().currentUser?.uid {

        let dbRef = Database.database().reference()
        dbRef.child("Users Info").child(userID).updateChildValues(["badge":"0"], withCompletionBlock: { (err, ref) in
            if err != nil {
                print(err!)
                return
            }
        })

    }


}

func applicationWillTerminate(_ application: UIApplication) {
    // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}


}

, и здесь ошибка появляется из AppDelegate

func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {

    InstanceID.instanceID().setAPNSToken(deviceToken, type: InstanceIDAPNSTokenType.sandbox)
}

Ответы [ 2 ]

0 голосов
/ 06 октября 2018

Я удалил следующий код

InstanceID.instanceID().setAPNSToken(deviceToken, type: InstanceIDAPNSTokenType.sandbox)

и заменил его на

Messaging.messaging().apnsToken = deviceToken

, проверено и работало нормально!

0 голосов
/ 05 октября 2018

Убедитесь, что вы используете Firebase 5.x и установите токен APNS с помощью класса сообщений Firebase вместо InstanceID.

См. https://firebase.google.com/docs/cloud-messaging/ios/client

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...