Skip to content

Commit aa591ff

Browse files
authored
Log direct-channel state changes to console (firebase#287)
1 parent 0a01a28 commit aa591ff

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

Example/Messaging/App/iOS/AppDelegate.swift

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
5151
FirebaseApp.configure()
5252
Messaging.messaging().delegate = self
5353
Messaging.messaging().shouldEstablishDirectChannel = true
54+
// Just for logging to the console when we establish/tear down our socket connection.
55+
listenForDirectChannelStateChanges();
5456

5557
NotificationsController.configure()
5658

@@ -126,3 +128,12 @@ extension AppDelegate: MessagingDelegate {
126128
}
127129
}
128130

131+
extension AppDelegate {
132+
func listenForDirectChannelStateChanges() {
133+
NotificationCenter.default.addObserver(self, selector: #selector(onMessagingDirectChannelStateChanged(_:)), name: .MessagingConnectionStateChanged, object: nil)
134+
}
135+
136+
func onMessagingDirectChannelStateChanged(_ notification: Notification) {
137+
print("FCM Direct Channel Established: \(Messaging.messaging().isDirectChannelEstablished)")
138+
}
139+
}

0 commit comments

Comments
 (0)