Skip to content

Commit 80a4512

Browse files
Enable watchOS for Remote Config and ABTesting (#7481)
1 parent e1603e9 commit 80a4512

File tree

9 files changed

+50
-16
lines changed

9 files changed

+50
-16
lines changed

.github/workflows/abtesting.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
runs-on: macOS-latest
2020
strategy:
2121
matrix:
22-
target: [ios, tvos, macos]
22+
target: [ios, tvos, macos, watchos]
2323
steps:
2424
- uses: actions/checkout@v2
2525
- name: Setup Bundler

.github/workflows/remoteconfig.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949

5050
strategy:
5151
matrix:
52-
target: [ios, tvos, macos]
52+
target: [ios, tvos, macos, watchos]
5353
steps:
5454
- uses: actions/checkout@v2
5555
- name: Setup Bundler

Example/watchOSSample/Podfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ target 'SampleWatchAppWatchKitExtension' do
1212
pod 'FirebaseCoreDiagnostics', :path => '../../'
1313
pod 'FirebaseInstallations', :path => '../../'
1414
pod 'FirebaseStorage', :path => '../../'
15+
pod 'FirebaseRemoteConfig', :path => '../../'
16+
pod 'FirebaseABTesting', :path => '../../'
17+
1518

1619
end
1720

Example/watchOSSample/SampleWatchAppWatchKitExtension/ExtensionDelegate.swift

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,30 +16,42 @@ import WatchKit
1616

1717
import FirebaseCore
1818
import FirebaseMessaging
19+
import FirebaseRemoteConfig
1920

2021
/// Entry point of the watch app.
2122
class 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

FirebaseABTesting.podspec

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,15 @@ Firebase Cloud Messaging and Firebase Remote Config in your app.
2121
}
2222

2323
s.social_media_url = 'https://twitter.com/Firebase'
24-
s.ios.deployment_target = '10.0'
25-
s.osx.deployment_target = '10.12'
26-
s.tvos.deployment_target = '10.0'
24+
ios_deployment_target = '10.0'
25+
osx_deployment_target = '10.12'
26+
tvos_deployment_target = '10.0'
27+
watchos_deployment_target = '6.0'
28+
29+
s.ios.deployment_target = ios_deployment_target
30+
s.osx.deployment_target = osx_deployment_target
31+
s.tvos.deployment_target = tvos_deployment_target
32+
s.watchos.deployment_target = watchos_deployment_target
2733

2834
s.cocoapods_version = '>= 1.4.0'
2935
s.prefix_header_file = false
@@ -44,6 +50,7 @@ Firebase Cloud Messaging and Firebase Remote Config in your app.
4450

4551
s.test_spec 'unit' do |unit_tests|
4652
unit_tests.scheme = { :code_coverage => true }
53+
unit_tests.platforms = {:ios => '10.0', :osx => '10.12', :tvos => '10.0'}
4754
unit_tests.source_files = 'FirebaseABTesting/Tests/Unit/**/*.[mh]'
4855
unit_tests.resources = 'FirebaseABTesting/Tests/Unit/Resources/*.txt'
4956
unit_tests.requires_app_host = true

FirebaseABTesting/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# unreleased
2+
- [added] Added community support for watchOS. (#7481)
3+
14
# v7.0.0
25
- [removed] Removed `FIRExperimentController.updateExperiments(serviceOrigin:events:policy:lastStartTime:payloads:)`, which was deprecated. (#6543)
36

FirebaseRemoteConfig.podspec

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,15 @@ app update.
1818
:tag => 'CocoaPods-' + s.version.to_s
1919
}
2020
s.social_media_url = 'https://twitter.com/Firebase'
21-
s.ios.deployment_target = '10.0'
22-
s.osx.deployment_target = '10.12'
23-
s.tvos.deployment_target = '10.0'
21+
ios_deployment_target = '10.0'
22+
osx_deployment_target = '10.12'
23+
tvos_deployment_target = '10.0'
24+
watchos_deployment_target = '6.0'
25+
26+
s.ios.deployment_target = ios_deployment_target
27+
s.osx.deployment_target = osx_deployment_target
28+
s.tvos.deployment_target = tvos_deployment_target
29+
s.watchos.deployment_target = watchos_deployment_target
2430

2531
s.cocoapods_version = '>= 1.4.0'
2632
s.prefix_header_file = false

FirebaseRemoteConfig/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# unreleased
2+
- [added] Added community support for watchOS. (#7481)
3+
14
# v7.6.0
25
- [fixed] Fixed build warnings introduced with Xcode 12.5. (#7432)
36

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,15 +253,15 @@ macOS/tvOS/watchOS/Catalyst.
253253
To install, add a subset of the following to the Podfile:
254254

255255
```
256-
pod 'Firebase/ABTesting' # No watchOS support yet
256+
pod 'Firebase/ABTesting'
257257
pod 'Firebase/Auth' # Limited watchOS support
258258
pod 'Firebase/Crashlytics'
259259
pod 'Firebase/Database' # No watchOS support yet
260260
pod 'Firebase/Firestore' # No watchOS support yet
261261
pod 'Firebase/Functions' # No watchOS support yet
262262
pod 'Firebase/Messaging'
263263
pod 'Firebase/Performance' # No macOS, tvOS, watchOS, and Catalyst support yet
264-
pod 'Firebase/RemoteConfig' # No watchOS support yet
264+
pod 'Firebase/RemoteConfig'
265265
pod 'Firebase/Storage'
266266
```
267267

0 commit comments

Comments
 (0)