aboutsummaryrefslogtreecommitdiffhomepage
path: root/Example
diff options
context:
space:
mode:
authorGravatar Riz <rsattar@gmail.com>2017-05-19 10:43:03 -0700
committerGravatar GitHub <noreply@github.com>2017-05-19 10:43:03 -0700
commited1b6098528f62b75c1d085299d02ace49df208e (patch)
tree6e3d334aa2945e97ac144967452fe96f49fa9d6d /Example
parent1634228abb24cbb39ff5dc486df02ac6f53a31bd (diff)
Enable direct channel in the sample app (#7)
This shows the simple property, shouldEstablishDirectChannel, to open a new channel, and how to show incoming messages with the iOS 10 delegate handler
Diffstat (limited to 'Example')
-rw-r--r--Example/Messaging/App/AppDelegate.swift14
1 files changed, 14 insertions, 0 deletions
diff --git a/Example/Messaging/App/AppDelegate.swift b/Example/Messaging/App/AppDelegate.swift
index 0f40a4e..ee092a9 100644
--- a/Example/Messaging/App/AppDelegate.swift
+++ b/Example/Messaging/App/AppDelegate.swift
@@ -50,6 +50,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
FirebaseApp.configure()
Messaging.messaging().delegate = self
+ Messaging.messaging().shouldEstablishDirectChannel = true
NotificationsController.configure()
@@ -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)")
+ }
}