[英]Firebase Messaging iOS 14
我已經在我的應用程序中設置了 Firebase Cloud Messaging 有一段時間了。 我最近將我的一台設備更新為 iOS 14,並停止在該設備上接收它們。 具有 iOS 13 的不同設備仍可接收它們。 如果這是一個愚蠢的問題,我很抱歉哈哈,但這是我的應用程序代表:
let appDelegate : AppDelegate = UIApplication.shared.delegate as! AppDelegate
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate {
var customerId = ""
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
application.registerForRemoteNotifications()
FirebaseApp.configure()
// Update this to your stripe PUBLISHABLE KEY
STPPaymentConfiguration.shared().publishableKey = "private"
let apiToken = "private"
EasyPostApi.sharedInstance.setCredentials(apiToken, baseUrl: "https://api.easypost.com/v2/")
STPTheme.default().accentColor = .red
Messaging.messaging().delegate = self
return true
}
// MARK: UISceneSession Lifecycle
func application(_ application: UIApplication, configurationForConnecting connectingSceneSession: UISceneSession, options: UIScene.ConnectionOptions) -> UISceneConfiguration {
// Called when a new scene session is being created.
// Use this method to select a configuration to create the new scene with.
return UISceneConfiguration(name: "Default Configuration", sessionRole: connectingSceneSession.role)
}
func application(_ application: UIApplication, didDiscardSceneSessions sceneSessions: Set<UISceneSession>) {
// Called when the user discards a scene session.
// If any sessions were discarded while the application was not running, this will be called shortly after application:didFinishLaunchingWithOptions.
// Use this method to release any resources that were specific to the discarded scenes, as they will not return.
}
func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
Messaging.messaging().apnsToken = deviceToken
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {
print(userInfo)
print("test")
}
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
print(userInfo)
print("test")
completionHandler(UIBackgroundFetchResult.newData)
}
func registerForPushNotifications() {
// 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
Messaging.messaging().delegate = self
InstanceID.instanceID().instanceID { (result, error) in
if let error = error {
print("Error fetching remote instance ID: \(error)")
} else if let result = result {
print("Remote instance ID token: \(result.token)")
}
}
}
}
我嘗試使用 firebase 控制台中的“測試”按鈕發送消息,並像正常一樣發布消息。 它確實正確注冊了通知,並且在檢查設置后,它看起來仍然正確。
我有同樣的問題。 我現在發現的一個修復是禁用方法混合:
FirebaseAppDelegateProxyEnabled
並將其設置為 FALSE(布爾值 0) 看起來您已經設置了didRegisterForRemoteNotificationsWithDeviceToken
,所以保持不變。
希望這可以幫助!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.