0
我有一個Firebase Remote通知未顯示的問題。我的通知已在Target - >功能中啓用,並且Firebase也已安裝。在Firebase網站上,當我嘗試發送通知時,它會立即關閉。收到0個設備。Firebase |遠程通知不會顯示,swift 3.0
這是我的代碼:
import UIKit
import UserNotifications
import Siren
import Firebase
import FirebaseDatabase
import FirebaseInstanceID
import FirebaseMessaging
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
var window: UIWindow?
override init() {
super.init()
FIRApp.configure()
FIRDatabase.database().persistenceEnabled = true
}
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
//
let notificationSettings = UIUserNotificationSettings(types: [.badge, .alert, .sound], categories: nil)
UIApplication.shared.registerUserNotificationSettings(notificationSettings)
application.registerForRemoteNotifications()
application.registerUserNotificationSettings(notificationSettings)
return true
}
而這正是它表明在火力地堡:
如果您需要任何其他信息,只問。
感謝您的幫助。
UPDATE(我添加了一些代碼):
的appDelegate:
func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable: Any],
fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
// If you are receiving a notification message while your app is in the background,
// this callback will not be fired till the user taps on the notification launching the application.
// TODO: Handle data of notification
// Print message ID.
print("Message ID: \(userInfo["gcm.message_id"]!)")
// Print full message.
print("%@", userInfo)
}
// [END receive_message]
// [START refresh_token]
func tokenRefreshNotification(_ notification: Notification) {
if let refreshedToken = FIRInstanceID.instanceID().token() {
print("InstanceID token: \(refreshedToken)")
}
// Connect to FCM since connection may have failed when attempted before having a token.
connectToFcm()
}
didFinishLaunchingWithOptions:
// Add observer for InstanceID token refresh callback.
NotificationCenter.default.addObserver(self,
selector: #selector(self.tokenRefreshNotification),
name: .firInstanceIDTokenRefresh,
object: nil)
其他代碼:
// [START connect_to_fcm]
func connectToFcm() {
FIRMessaging.messaging().connect { (error) in
if (error != nil) {
print("Unable to connect with FCM. \(error)")
} else {
print("Connected to FCM.")
}
}
}
// [END connect_to_fcm]
func applicationDidBecomeActive(_ application: UIApplication) {
connectToFcm()
}
// [START disconnect_from_fcm]
func applicationDidEnterBackground(_ application: UIApplication) {
FIRMessaging.messaging().disconnect()
添加了所有內容。它說每一個開放的「連接到FMC」。但是如果我嘗試發送通知,它仍然不會顯示,並且Firebase沒有響應(Insant finish)您能幫助我嗎?謝啦! – user6083214
您是否像我說的那樣從info.plist中刪除了該行?你確定你的設置允許通知嗎? –
FirebaseAppDelegateProxyEnabled已被刪除,就像你說的。通知位於目標 - >'AppName' - >功能 - >推送通知設置爲ON! – user6083214