我正在使用 swift3。当我的应用程序收到 FCM
消息数据时,我想在 UIViewController
中向 tableview
显示 FCM
消息。我有我的 fcm 数据在 appDelegate
中使用以下代码..但我不知道如何在 UIViewController
中获取数据。
func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (_ options: UNNotificationPresentationOptions) -> Void) {
let message : UNNotificationPresentationOptions = .alert
//GlobalVariables.notification_message = getAlert(notification: .alert)
if UIApplication.shared.applicationState == .active { // In iOS 10 if app is in foreground do nothing.
print("active****")
print("\(notification.request.content.userInfo)")
completionHandler([message, .sound])
} else {
print("Not active****")
completionHandler([message, .badge, .sound])
}
}
请帮帮我 提前致谢
最佳答案
在您的 AppDelegate 上设置一个变量,然后使用它:
- AppDelegate 在
window?.rootViewController
上的 didFinishLaunchingWithOptions - 你的 View Controller 通过调用
(UIApplication.shared.delegate as?AppDelegate)?.yourVariable
我建议在使用后将 AppDelegate 中的变量设置为 nil,以防止使用相同的通知数据两次。
关于ios - 如何在 Swift3 的 UIViewController 中获取 FCM 消息?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49207329/