I use Firebase as my backend and I use Cloud Messaging for Push Notifications , but my application only receives notifications when the application is open (and Push Notifications do not appear when the application is open). I checked the Firebase docs and other code examples and I cannot find anything specifically, I am missing and I get the correct output when the application is open. The problem is that notifications do not appear if the notification banner is not displayed at all outside the application, only the output from the xcode console. This is my code:
import UIKit import Firebase import UserNotifications import FirebaseMessaging @UIApplicationMain class AppDelegate: UIResponder, UIApplicationDelegate { var window: UIWindow? override init() { FIRApp.configure() //this is the changed version. if let token = FIRInstanceID.instanceID().token(){ print("Target Token ID: \(token)") } let token = FIRInstanceID.instanceID().token()! print("TOKEN:\(token)") } func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool { // Override point for customization after application launch. //FIRApp.configure() if
This is the output when a message is received:
%@ [AnyHashable("notification"): { body = myMSG; e = 1; }, AnyHashable("from"): 492525072004, AnyHashable("collapse_key"): com.myApp] QQQQQ
Again, the output is only displayed inside the application, which hits the point of Push Notifications. Also, no banner is displayed, which, I believe, is due to the fact that Push notifications for the application are not displayed when inside the application.
source share