我的Firebase Cloud Messaging大约在2周前可以正常工作(在真实设备上的屏幕上弹出通知)。我在应用程序上开发了其他东西(刷新表)。然后我回到FCM,它停了下来。 我已经阅读了网上的几乎所有链接。
我的AppDelegate:
import UIKit
import CoreData
import UserNotifications
import Firebase
import FirebaseMessaging
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate, UNUserNotificationCenterDelegate, MessagingDelegate {
var window: UIWindow?
let defaults = Defaults()
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
let appDelegate = UIApplication.shared.delegate as! AppDelegate
appDelegate.window?.rootViewController = rootVC
//Permission to send notifications
UNUserNotificationCenter.current().delegate = self
UNUserNotificationCenter.current().requestAuthorization(options: [.alert, .badge, .sound]) { (granted, error) in
if error != nil {
print("Request authorization notification failed!")
} else {
print("Request authorization notification succeeded!")
}
}
UIApplication.shared.setMinimumBackgroundFetchInterval( 11 )
let autorizacao: UNAuthorizationOptions = [.badge, .alert, .sound]
UNUserNotificationCenter.current().requestAuthorization(options: autorizacao) { ( granted, error )in
Messaging.messaging().delegate = self
Messaging.messaging().shouldEstablishDirectChannel = true
}
application.registerForRemoteNotifications()
FirebaseApp.configure()
return true
}
func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
print("token: \(fcmToken)")
if defaults.getTokenFCM() == "" {
defaults.setTokenFCM(fcmToken)
}
}
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
print(remoteMessage.appData)
}
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
completionHandler([.alert, .sound])
}
}
它打印:“请求授权通知成功!”
我可以在控制台上看到我的令牌,也可以看到我从console.firebase.google.com
发送的高优先级消息。
控制台上没有错误。
是的,我重新创建了APN证书以尝试解决,但没有成功。我更新了钥匙链和Firebase配置。
“功能推送通知”已打开并且配置正确。以及在后台模式下的远程通知。
firebaseAppDelegateProxyEnabled布尔值info.plist上的否
我尝试接收推送前景和背景,两者均无效。
我正在使用Xcode 10.1,iPhone(真实设备)为6s。
我真的不知道还能尝试什么。
请帮忙吗?