Ios 使用未解析标识符';InstancedInstanceType';
未解决的标识符问题以前已经解决,我执行了从repo到安装(从pod中移除firebase)的所有步骤,并在pod中重新安装firebase…等等,但它仍然没有解决这个问题。这个问题和其他问题是在我更新pod后产生的。此问题发生在AppDelegate中的函数中 这是我的Ios 使用未解析标识符';InstancedInstanceType';,ios,swift,firebase,Ios,Swift,Firebase,未解决的标识符问题以前已经解决,我执行了从repo到安装(从pod中移除firebase)的所有步骤,并在pod中重新安装firebase…等等,但它仍然没有解决这个问题。这个问题和其他问题是在我更新pod后产生的。此问题发生在AppDelegate中的函数中 这是我的AppDelegate.swift import UIKit import Firebase import FirebaseMessaging import FirebaseAuth import FirebaseDatabase
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)
}
确保您在Firebase 5.x上,并将APNS令牌与Firebase消息传递类而不是InstanceID一起使用
请参见确保您使用的是Firebase 5.x,并将APNS令牌设置为Firebase消息传递类,而不是InstanceID
请参见我删除了以下代码
InstanceID.instanceID().setAPNSToken(deviceToken, type: InstanceIDAPNSTokenType.sandbox)
并将其替换为
Messaging.messaging().apnsToken = deviceToken
测试和工作良好 我删除了以下代码
InstanceID.instanceID().setAPNSToken(deviceToken, type: InstanceIDAPNSTokenType.sandbox)
并将其替换为
Messaging.messaging().apnsToken = deviceToken
测试和工作良好 这是什么?你想用它做什么?我在示例ID中没有看到它。它是用于远程通知的。这是什么
setAPNSToken
,您想用它做什么?我在示例ID中没有看到它。它用于远程通知。谢谢Paul!我猜SetAspenstoken已经不存在了。我替换为Messaging.Messaging().apnsToken=deviceToken。我最终不确定这是否是解决方案,但效果很好。谢谢保罗!我猜SetAspenstoken已经不存在了。我替换为Messaging.Messaging().apnsToken=deviceToken。我最终不确定这是否是解决方案,但效果很好。