@@ -16,30 +16,42 @@ import WatchKit
16
16
17
17
import FirebaseCore
18
18
import FirebaseMessaging
19
+ import FirebaseRemoteConfig
19
20
20
21
/// Entry point of the watch app.
21
22
class ExtensionDelegate : NSObject , WKExtensionDelegate , MessagingDelegate {
22
23
/// Initialize Firebase service here.
23
24
func applicationDidFinishLaunching( ) {
24
25
FirebaseApp . configure ( )
25
26
let center = UNUserNotificationCenter . current ( )
26
- center. requestAuthorization ( options: [ . alert, . sound] ) { granted, error in
27
+ center. requestAuthorization ( options: [ . alert, . sound] ) { granted, _ in
27
28
if granted {
28
29
WKExtension . shared ( ) . registerForRemoteNotifications ( )
29
30
}
30
31
}
31
32
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
+ }
32
44
}
33
45
34
46
/// 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! )
37
49
Messaging . messaging ( ) . subscribe ( toTopic: " watch " ) { error in
38
- if error != nil {
50
+ guard error == nil else {
39
51
print ( " error: " + error. debugDescription)
40
- } else {
41
- print ( " Successfully subscribed to topic " )
52
+ return
42
53
}
54
+ print ( " Successfully subscribed to topic " )
43
55
}
44
56
}
45
57
0 commit comments