@@ -16,30 +16,42 @@ import WatchKit
1616
1717import FirebaseCore
1818import FirebaseMessaging
19+ import FirebaseRemoteConfig
1920
2021/// Entry point of the watch app.
2122class ExtensionDelegate : NSObject , WKExtensionDelegate , MessagingDelegate {
2223 /// Initialize Firebase service here.
2324 func applicationDidFinishLaunching( ) {
2425 FirebaseApp . configure ( )
2526 let center = UNUserNotificationCenter . current ( )
26- center. requestAuthorization ( options: [ . alert, . sound] ) { granted, error in
27+ center. requestAuthorization ( options: [ . alert, . sound] ) { granted, _ in
2728 if granted {
2829 WKExtension . shared ( ) . registerForRemoteNotifications ( )
2930 }
3031 }
3132 Messaging . messaging ( ) . delegate = self
33+ let remoteConfig = RemoteConfig . remoteConfig ( )
34+ remoteConfig. fetchAndActivate { _, error in
35+ guard error == nil else {
36+ print ( " error: " + error. debugDescription)
37+ return
38+ }
39+ let defaultOutput = " You have not set up a 'test' key in Remote Config console. "
40+ let configValue : String =
41+ remoteConfig [ " test " ] . stringValue ?? defaultOutput
42+ print ( " value: \n " + configValue)
43+ }
3244 }
3345
3446 /// MessagingDelegate
35- func messaging( _ messaging : Messaging , didReceiveRegistrationToken fcmToken: String ) {
36- print ( " token: \n " + fcmToken)
47+ func messaging( _: Messaging , didReceiveRegistrationToken fcmToken: String ? ) {
48+ print ( " token: \n " + fcmToken! )
3749 Messaging . messaging ( ) . subscribe ( toTopic: " watch " ) { error in
38- if error != nil {
50+ guard error == nil else {
3951 print ( " error: " + error. debugDescription)
40- } else {
41- print ( " Successfully subscribed to topic " )
52+ return
4253 }
54+ print ( " Successfully subscribed to topic " )
4355 }
4456 }
4557
0 commit comments