Firebase CloudMessaging无法正常运行Swift 5

问题描述

我正在项目中实施Firebase Cloud Messaging解决方案。我已按照所需的所有步骤进行操作,但是从Firebase控制台发送测试消息或发布新消息时,仍然没有收到任何通知

这是我的代码

  <subsystem xmlns="urn:jboss:domain:datasources:5.0">
     <datasources>
       ​<drivers>
         ​<driver name="h2" module="com.h2database.h2">
           ​<xa-datasource-class>org.h2.jdbcx.JdbcDataSource</xa-datasource-class>
         ​</driver>
       ​</drivers>
       ...
       <datasource jndi-name="java:jboss/datasources/KeycloakDS" pool-name="KeycloakDS" enabled="true" use-java-context="true">
           <driver>h2</driver>
           <connection-url>jdbc:h2:${jboss.server.data.dir}/keycloak;AUTO_SERVER=TRUE</connection-url>
           <security>
               <user-name>sa</user-name>
               <password>?</password>
           </security>
       </datasource>
        ...
     </datasources>

我从功能菜单中启用了推送通知和远程通知

生成了Auth APNs密钥,并将其上传到Firebase控制台中的项目中。

我的配置文件包括推送通知

我确实看到import UIKit import FirebaseCore import FirebaseMessaging import UserNotifications @UIApplicationMain class AppDelegate: UIResponder,UIApplicationDelegate { // Variables var window: UIWindow? let gcmMessageIDKey = "gcm.message_id" // Functions func application(_ application: UIApplication,didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool { FirebaseApp.configure() FirebaseAuth.login(email: FirebaseAuth.adminUser.email,password: FirebaseAuth.adminUser.password) { (userAuthenticaed) in if userAuthenticaed { FirebaseDatabase.initDatabase() FirebaseStorage.initStorage() FirebaseDatabase.getContactDetails() FirebaseDatabase.getInventory() FirebaseAuth.logout() FirebaseAuth.user = nil } } Messaging.messaging().delegate = self self.registerForPushNotifications(application: application) return true } func registerForPushNotifications(application: UIApplication) { if #available(iOS 10.0,*) { UNUserNotificationCenter.current().delegate = self let authOptions: UNAuthorizationoptions = [.alert,.badge,.sound] UNUserNotificationCenter.current().requestAuthorization( options: authOptions,completionHandler: {_,_ in }) } else { let settings: UIUserNotificationSettings = UIUserNotificationSettings(types: [.alert,.sound],categories: nil) application.registerUserNotificationSettings(settings) } application.registerForRemoteNotifications() } func application(_ application: UIApplication,didReceiveRemoteNotification userInfo: [AnyHashable: Any]) { if let messageID = userInfo[gcmMessageIDKey] { print("Message ID: \(messageID)") } print(userInfo) } func application(_ application: UIApplication,didReceiveRemoteNotification userInfo: [AnyHashable: Any],fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) { if let messageID = userInfo[gcmMessageIDKey] { print("Message ID: \(messageID)") } print(userInfo) completionHandler(UIBackgroundFetchResult.newData) } func application(_ application: UIApplication,didFailToRegisterForRemoteNotificationsWithError error: Error) { print("Unable to register for remote notifications: \(error.localizedDescription)") } func application(_ application: UIApplication,didRegisterForRemoteNotificationsWithDevicetoken devicetoken: Data) { print("APNs token retrieved: \(devicetoken)") } } @available(iOS 10,*) extension AppDelegate : UNUserNotificationCenterDelegate { func userNotificationCenter(_ center: UNUserNotificationCenter,willPresent notification: UNNotification,withCompletionHandler completionHandler: @escaping (UNNotificationPresentationoptions) -> Void) { let userInfo = notification.request.content.userInfo if let messageID = userInfo[gcmMessageIDKey] { print("Message ID: \(messageID)") } print(userInfo) completionHandler([[.alert,.sound]]) } } extension AppDelegate : MessagingDelegate { func messaging(_ messaging: Messaging,didReceiveRegistrationToken fcmToken: String) { print("Firebase registration token: \(fcmToken)") let dataDict:[String: String] = ["token": fcmToken] NotificationCenter.default.post(name: Notification.Name("FCMToken"),object: nil,userInfo: dataDict) print(fcmToken) } } didRegisterForRemoteNotificationsWithDevicetoken调用,因此注册成功,但是,没有消息到达。

我想念什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)