title: Firebase Cloud Message Notification being received in Console but not being displayed in phone - Swift App
body: <p>So I'm trying to implement Cloud Messaging with Firebase Functions for a message center in my app. My firebase function says it is already working and I do receive the message in my console log, however, the notification is not being deployed in my phone on background mode.</p>
  <p>I've implemented the permission to receive notifications once my user is logged in in Home View. This is my code:</p>
  <pre class="lang-swift prettyprint-override"><code> func askNotificationPermission() {
          
          //Firebase Push Notifications
            UNUserNotificationCenter.current().delegate = self
  
            let authOptions: UNAuthorizationOptions = [.alert, .badge, .sound]
            UNUserNotificationCenter.current().requestAuthorization(
              options: authOptions,
              completionHandler: {_, _ in
                  print(&quot;HOLA TE DIERON PERMISO&quot;)
            })
          
              Messaging.messaging().shouldEstablishDirectChannel = true
          
            UIApplication.shared.registerForRemoteNotifications()
            Messaging.messaging().delegate = self
    
      }
  </code></pre>
  <p>I've implemented the necessary Firebase functions in <code>didFinishLaunchingApplication</code>:</p>
  <pre><code>  func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -&gt; Bool {
      //MARK: Firebase
      FirebaseApp.configure()
      
      //Firebase Cloud Messaging
        Messaging.messaging().delegate = self
      
      
      //MARK: Others
      //KeyboardManager
      IQKeyboardManager.shared.enable = true
      
      //navbar
      let navControl = UINavigationBar.appearance()
      let myColor : UIColor = UIColor(red: 0, green: 0.1333, blue: 0.3176, alpha: 1)
      navControl.tintColor = myColor
  
      return true
  }
  </code></pre>
  <p>And this is my extension for the Notifications within App Delegate:</p>
  <pre class="lang-swift prettyprint-override"><code>    extension AppDelegate: UNUserNotificationCenterDelegate, MessagingDelegate {
      
      func applicationDidEnterBackground(_ application: UIApplication) {
          Messaging.messaging().shouldEstablishDirectChannel = true
      }
      
      func messaging(_ messaging: Messaging, didReceiveRegistrationToken fcmToken: String) {
             
             let dataDict: [String: String] = [&quot;token&quot;: fcmToken]
             NotificationCenter.default.post(name: Notification.Name(&quot;FCMToken&quot;), object: nil, userInfo: dataDict)
             
             //TODO: If necessary send token to application server
             //Note: This callback is fired at each app startup and whenever a new token is generated
         }
      
      func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
          
          Messaging.messaging().appDidReceiveMessage(userInfo)
          
          if let messageID = userInfo[gcmMessageIDKey] {
             print(&quot;Message ID: \(messageID)&quot;)
           }
  
           // Print full message.
           print(&quot;USER INFO: &quot;,userInfo)
      }
      
      func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any], fetchCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -&gt; Void) {
          print(userInfo)
          completionHandler(UIBackgroundFetchResult.newData)
          print(&quot;USER INFO IN DID RECEIVE REMOTE NOTIFICAITON:&quot;, userInfo, UIBackgroundFetchResult.newData)
      }
      
      func userNotificationCenter(_ center: UNUserNotificationCenter,
                                  willPresent notification: UNNotification,
                                  withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -&gt; Void) {
          
          let userInfo = notification.request.content.userInfo as! [String:Any]
  
          completionHandler([.alert, .badge, .sound])
          print(&quot;HOLI&quot;)
  
      }
  }
  </code></pre>
  <p>I don't know what might be the problem and why I am receiving the information in the console but it is not being pushed to the app. I've searched through several stackoverflow questions but none have worked.</p>
  <p>This is what my console logs:</p>
  <blockquote>
  <p>2020-08-06 11:06:06.804344-0500 FleaMarket_UserSide[13985:4429211] [] nw_read_request_report [C2] Receive failed with error &quot;Software caused connection abort&quot;
  [AnyHashable(&quot;title&quot;): Jay Shetty Meditations, AnyHashable(&quot;aps&quot;): {
  &quot;content-available&quot; = 1;
  }, AnyHashable(&quot;gcm.message_id&quot;): 1596729966264394, AnyHashable(&quot;message&quot;): did you get it?, AnyHashable(&quot;google.c.sender.id&quot;): 520471783461]
  USER INFO IN DID RECEIVE REMOTE NOTIFICAITON: [AnyHashable(&quot;title&quot;): Jay Shetty Meditations, AnyHashable(&quot;aps&quot;): {
  &quot;content-available&quot; = 1;
  }, AnyHashable(&quot;gcm.message_id&quot;): 1596729966264394, AnyHashable(&quot;message&quot;): did you get it?, AnyHashable(&quot;google.c.sender.id&quot;): 520471783461] UIBackgroundFetchResult
  2020-08-06 11:06:06.835793-0500 FleaMarket_UserSide[13985:4429216] 6.27.0 - [Firebase/Firestore][I-FST000001] WatchStream (282c75618) Stream error: 'Unavailable: Socket is not connected'</p>
  </blockquote>