Skip to content

Commit bfa71ff

Browse files
sebalandameter
andauthored
feat: Adding support for tvOS and watchOS (#32)
* feat: add support for watchOS * bump minimum watchOS support v7 * use WKExtension instead of WKApplication to support versions of Xcode prior to 14.0 * feat: add support for tvOS * feat: Adding tvOS minimum version * Adding tvOS and watchOS builds to CI --------- Co-authored-by: Chris Ameter <29186822+ameter@users.noreply.github.com>
1 parent 01460c0 commit bfa71ff

File tree

6 files changed

+83
-2
lines changed

6 files changed

+83
-2
lines changed

.circleci/config.yml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@ jobs:
3838
name: Unit tests
3939
command: bundle exec fastlane mac tests
4040

41+
build-test-tvos:
42+
<<: *default-executor
43+
44+
steps:
45+
- checkout
46+
- ruby/install-deps
47+
- run:
48+
name: Unit tests
49+
command: bundle exec fastlane tvos tests
50+
51+
build-test-watchos:
52+
<<: *default-executor
53+
54+
steps:
55+
- checkout
56+
- ruby/install-deps
57+
- run:
58+
name: Unit tests
59+
command: bundle exec fastlane watchos tests
60+
4161
release:
4262
<<: *default-executor
4363

@@ -74,13 +94,17 @@ workflows:
7494
jobs:
7595
- build-test-ios
7696
- build-test-macos
97+
- build-test-tvos
98+
- build-test-watchos
7799
- release:
78100
filters:
79101
branches:
80102
only: release
81103
requires:
82104
- build-test-ios
83105
- build-test-macos
106+
- build-test-tvos
107+
- build-test-watchos
84108
context: amplify-swift-aws-oidc
85109

86110
- publish-doc:

Package.swift

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@ import PackageDescription
55

66
let package = Package(
77
name: "AmplifyUtilsNotifications",
8-
platforms: [.iOS(.v13), .macOS(.v10_15)],
8+
platforms: [
9+
.iOS(.v13),
10+
.macOS(.v10_15),
11+
.tvOS(.v13),
12+
.watchOS(.v7)
13+
],
914
products: [
1015
.library(
1116
name: "AmplifyUtilsNotifications",

Sources/AmplifyUtilsNotifications/AUNotificationPermissions.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,9 @@
88
import Foundation
99
import UserNotifications
1010

11-
#if canImport(AppKit)
11+
#if canImport(WatchKit)
12+
import WatchKit
13+
#elseif canImport(AppKit)
1214
import AppKit
1315
typealias Application = NSApplication
1416
#elseif canImport(UIKit)
@@ -57,7 +59,11 @@ public class AUNotificationPermissions {
5759
/// Register device with APNs
5860
public static func registerForRemoteNotifications() async {
5961
await MainActor.run {
62+
#if canImport(WatchKit)
63+
WKExtension.shared().registerForRemoteNotifications()
64+
#else
6065
Application.shared.registerForRemoteNotifications()
66+
#endif
6167
}
6268
}
6369
}

Sources/AmplifyUtilsNotifications/AUNotificationService.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8+
#if !os(tvOS)
9+
810
import UserNotifications
911
import os.log
1012

@@ -100,3 +102,5 @@ open class AUNotificationService: UNNotificationServiceExtension {
100102
}
101103
}
102104
}
105+
106+
#endif

Tests/AmplifyUtilsNotificationsTests/AUNotificationServiceTests.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// SPDX-License-Identifier: Apache-2.0
66
//
77

8+
#if !os(tvOS)
9+
810
import XCTest
911
@testable import AmplifyUtilsNotifications
1012
@testable import UserNotifications
@@ -149,3 +151,5 @@ final class AUNotificationServiceTests: XCTestCase {
149151
waitForExpectations(timeout: 1)
150152
}
151153
}
154+
155+
#endif

fastlane/Fastfile

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,3 +154,41 @@ platform :mac do
154154
)
155155
end
156156
end
157+
158+
platform :tvos do
159+
before_all do
160+
setup_circle_ci
161+
end
162+
163+
desc "Run all the tests on tvOS"
164+
lane :tests do
165+
run_tests(
166+
clean: true,
167+
result_bundle: true,
168+
include_simulator_logs: false,
169+
scheme: "AmplifyUtilsNotifications",
170+
package_path: ".",
171+
sdk: "appletvsimulator",
172+
destination: "platform=tvOS Simulator,name=Apple TV 4K (3rd generation),OS=latest",
173+
)
174+
end
175+
end
176+
177+
platform :watchos do
178+
before_all do
179+
setup_circle_ci
180+
end
181+
182+
desc "Run all the tests on watchOS"
183+
lane :tests do
184+
run_tests(
185+
clean: true,
186+
result_bundle: true,
187+
include_simulator_logs: false,
188+
scheme: "AmplifyUtilsNotifications",
189+
package_path: ".",
190+
sdk: "watchsimulator",
191+
destination: "platform=watchOS Simulator,name=Apple Watch Series 8 (45mm),OS=latest",
192+
)
193+
end
194+
end

0 commit comments

Comments
 (0)