Skip to content

Commit

Permalink
Enable direct channel in the sample app (firebase#7)
Browse files Browse the repository at this point in the history
This shows the simple property, shouldEstablishDirectChannel, to open a new channel, and how to show incoming messages with the iOS 10 delegate handler
  • Loading branch information
rsattar authored May 19, 2017
1 parent 5f993ed commit 6086d78
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Example/Messaging/App/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {

FirebaseApp.configure()
Messaging.messaging().delegate = self
Messaging.messaging().shouldEstablishDirectChannel = true

NotificationsController.configure()

Expand Down Expand Up @@ -110,5 +111,18 @@ extension AppDelegate: MessagingDelegate {
func messaging(_ messaging: Messaging, didRefreshRegistrationToken fcmToken: String) {
printFCMToken()
}

// Direct channel data messages are delivered here, on iOS 10.0+.
// The `shouldEstablishDirectChannel` property should be be set to |true| before data messages can
// arrive.
func messaging(_ messaging: Messaging, didReceive remoteMessage: MessagingRemoteMessage) {
// Convert to pretty-print JSON
guard let data =
try? JSONSerialization.data(withJSONObject: remoteMessage.appData, options: .prettyPrinted),
let prettyPrinted = String(data: data, encoding: .utf8) else {
return
}
print("Received direct channel message:\n\(prettyPrinted)")
}
}

0 comments on commit 6086d78

Please sign in to comment.