gpt4 book ai didi

ios - 使用未解析的标识符 'InstanceIDAPNSTokenType'

转载 作者:搜寻专家 更新时间:2023-11-01 05:54:54 26 4
gpt4 key购买 nike

未解析标识符的问题之前已经解决,我完成了从 repo 到安装(从 pod 中删除 firebase)和在 pod 中重新安装 firebase 的所有步骤...等等,但它仍然没有解决这个问题。这个问题连同其他问题是在我更新 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)
}

最佳答案

确保您使用的是 Firebase 5.x,并使用 Firebase Messaging 类而不是 InstanceID 设置 APNS token 。

参见 https://firebase.google.com/docs/cloud-messaging/ios/client

关于ios - 使用未解析的标识符 'InstanceIDAPNSTokenType',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52654934/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com