如何在我的应用程序上从firebase控制台进行检测

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何在我的应用程序上从firebase控制台进行检测相关的知识,希望对你有一定的参考价值。

现在我有1种方法来做推送通知。

我使用firebase控制台(https://console.firebase.google.com/),然后分配包ID并发送推送通知。

现在我有一个问题。

如何在我的应用程序上使用firebase控制台进行检测(使用swift)。

这是我的didReceiveRemoteNotification代码

didReceiveRemoteNotification Code

func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any]) {   
    if let messageID = userInfo[gcmMessageIDKey] {  
        print("Message ID1: (messageID)")  
    }  

    var pushId = userInfo["push-id"] as? String  
    if(pushId == nil){  
        pushId = "-1"  
    }  
    fcmAccessCount(pushId: pushId!)  
    badgeCount()  

    switch application.applicationState {  
    case .active:  
    break  
    case .inactive:  
    break  
    case .background:  
    break  
    default:  
    break  
    }  

    if let aps = userInfo["aps"] as? NSDictionary {  
        if let alert = aps["alert"] as? String {  
            let alert = UIAlertController(title: "message is... ", message: alert, preferredStyle: .alert)  
            alert.addAction(UIAlertAction(title: "OK", style: .default, handler: nil))  
            self.window?.rootViewController?.present(alert, animated: true, completion: nil)  
        }  
    }  
}
答案

请在App Delegate类中编写此代码,如下所示,并尝试 -

class AppDelegate: UIResponder, UIApplicationDelegate{




 }



    @available(ios 10, *)
        extension AppDelegate : UNUserNotificationCenterDelegate {

            // Receive displayed notifications for iOS 10 devices.
            func userNotificationCenter(_ center: UNUserNotificationCenter,
                                        willPresent notification: UNNotification,
                                        withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
                let userInfo = notification.request.content.userInfo
                //From here we will navigate to other screens:-


                print("User Info : (userInfo)")

                // Change this to your preferred presentation option
                //completionHandler([])
                completionHandler([.alert,.sound])
            }

            func userNotificationCenter(_ center: UNUserNotificationCenter,
                                        didReceive response: UNNotificationResponse,
                                        withCompletionHandler completionHandler: @escaping () -> Void) {
                let userInfo = response.notification.request.content.userInfo
                // From here we can navigat to required screens:-
                // Print full message.
                print(userInfo)

                completionHandler()
            }
        }

        extension AppDelegate : FIRMessagingDelegate {
            /// The callback to handle data message received via FCM for devices running iOS 10 or above.
            public func applicationReceivedRemoteMessage(_ remoteMessage: FIRMessagingRemoteMessage) {

            }

以上是关于如何在我的应用程序上从firebase控制台进行检测的主要内容,如果未能解决你的问题,请参考以下文章

颤动的firebase登录问题

如何仅在 HTTPS 上从 .htaccess 设置 HSTS 标头 [关闭]

如何在 Item Click 上从 FirebaseListAdapter 获取 obj 密钥。 Firebase 用户界面

如何从Button的onClick侦听器中删除Firebase DataBase

如何在 Android 上从 JWT 收集签名、标头和正文

检索子值 Failed-Firebase- Android