【问题标题】:How to detection from firebase console on my an application如何从我的应用程序上的 firebase 控制台检测
【发布时间】:2018-08-06 23:41:29
【问题描述】:

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

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

现在我有一个问题。

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

这是我的 didReceiveRemoteNotification 代码

didReceiveRemoteNotification 代码

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)  
        }  
    }  
}

【问题讨论】:

  • 我没有正确理解您的问题。你想达到什么目标?
  • 未解决的问题。
  • 对不起我的英语不好我编辑
  • 您要检查通知是否已发送到您的设备上?
  • 感谢您回复@iDeveloper。我想检查(检测)关于我的应用程序源代码的通知。

标签: ios swift curl push-notification firebase-console


【解决方案1】:

请在 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) {

            }

【讨论】:

    猜你喜欢
    • 2012-03-07
    • 2019-01-30
    • 2019-07-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-02-11
    相关资源
    最近更新 更多