Skip to content

shouldEstablishDirectChannel not establishing connection on first app launch #210

Closed
@alanscarpa

Description

@alanscarpa

Describe your environment

  • Xcode version: 8.3.3
  • Firebase 4.1.0
  • FirebaseAnalytics 4.0.3
  • FirebaseCore 4.0.5
  • FirebaseInstanceID 2.0.1
  • FirebaseMessaging 2.0.1
  • Firebase Product: Messaging

Describe the problem

When launching an app for the first time, or after deleting and re-installing, Messaging.messaging().shouldEstablishDirectChannel does not establish the socket connection. If I shut down the app, and re-open it, then the socket connection is established.

Steps to reproduce:

  1. Place this code in AppDelegate:
FirebaseApp.configure()
Messaging.messaging().delegate = self
Messaging.messaging().shouldEstablishDirectChannel = true
  1. Place this code anywhere after to check if connection is established:
    Messaging.messaging().isDirectChannelEstablished
    This always returns false.
  2. Listen for connection state change and observe that this notification never gets fired.
NotificationCenter.default.addObserver(self, selector:
            #selector(fcmConnectionStateChange), name:
            NSNotification.Name.MessagingConnectionStateChanged, object: nil)

That is the problem in a nutshell. If I simply kill the app, and re-launch it, everything works as expected. The socket connection is made and the MessagingConnectionStateChanged notification is fired.

Why is Messaging.messaging().shouldEstablishDirectChannel not connecting on my initial app launch?

Relevant Code:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
        window = UIWindow(frame: UIScreen.main.bounds)
        window!.rootViewController = RootViewController.shared
        window!.makeKeyAndVisible()

        setUpFirebase()
        setUpPushNotificationsForApplication(application)
        RootViewController.shared.goToLoginVC()
        
        return true
    }
    
    // MARK: - Firebase
    
    func setUpFirebase() {
        NotificationCenter.default.addObserver(self, selector:
            #selector(fcmConnectionStateChange), name:
            NSNotification.Name.MessagingConnectionStateChanged, object: nil)        
        FirebaseApp.configure()
        Messaging.messaging().delegate = self
        Messaging.messaging().shouldEstablishDirectChannel = true
    }
    
    // MARK: - Firebase Notifications
    
    func fcmConnectionStateChange() {
       // This is never called on app's first launch!!!
        print(Messaging.messaging().isDirectChannelEstablished)
    }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions