Skip to content

Commit 7c65f48

Browse files
rwarnerclaude
andcommitted
Use os(iOS) && !targetEnvironment(macCatalyst) for ActivityKit guards
Mac Catalyst reports os(iOS) as true but ActivityKit APIs are marked unavailable on it. Replace all ActivityKit-specific #if os(iOS) guards with #if os(iOS) && !targetEnvironment(macCatalyst) to exclude the code from Mac Catalyst compilation. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2a55d02 commit 7c65f48

9 files changed

Lines changed: 12 additions & 13 deletions

File tree

Sources/App/AppDelegate.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
374374
}
375375

376376
private func setupLiveActivityReattachment() {
377-
#if os(iOS)
377+
#if os(iOS) && !targetEnvironment(macCatalyst)
378378
if #available(iOS 17.2, *) {
379379
// Pre-warm the registry on the main thread before spawning background Tasks.
380380
// This avoids a lazy-init race if a push notification handler accesses it

Sources/App/Settings/LiveActivity/LiveActivitySettingsView.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if os(iOS)
1+
#if os(iOS) && !targetEnvironment(macCatalyst)
22
import ActivityKit
33
import Shared
44
import SwiftUI

Sources/App/Settings/Settings/SettingsItem.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ enum SettingsItem: String, Hashable, CaseIterable {
112112
case .notifications:
113113
SettingsNotificationsView()
114114
case .liveActivities:
115-
#if os(iOS)
115+
#if os(iOS) && !targetEnvironment(macCatalyst)
116116
if #available(iOS 17.2, *) {
117117
LiveActivitySettingsView()
118118
}

Sources/Shared/API/HAAPI.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import Version
1111
#if os(iOS)
1212
import Reachability
1313
#endif
14-
#if os(iOS)
14+
#if os(iOS) && !targetEnvironment(macCatalyst)
1515
import ActivityKit
1616
#endif
1717

@@ -562,7 +562,7 @@ public class HomeAssistantAPI {
562562
"push_token": pushID,
563563
]
564564

565-
#if os(iOS)
565+
#if os(iOS) && !targetEnvironment(macCatalyst)
566566
if #available(iOS 17.2, *) {
567567
// Advertise Live Activity support so HA can gate the UI and send
568568
// activity push tokens back to the relay server.

Sources/Shared/Environment/Environment.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ public class AppEnvironment {
140140
#endif
141141
}
142142

143-
#if os(iOS)
144-
#if os(iOS)
143+
#if os(iOS) && !targetEnvironment(macCatalyst)
145144
/// Call `_ = Current.liveActivityRegistry` on the main thread at launch (before any
146145
/// background thread can access it) to avoid a lazy-init race between concurrent callers.
147146
public lazy var liveActivityRegistry: LiveActivityRegistryProtocol? = {

Sources/Shared/LiveActivity/HALiveActivityAttributes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if os(iOS)
1+
#if os(iOS) && !targetEnvironment(macCatalyst)
22
import ActivityKit
33
import SwiftUI
44

Sources/Shared/LiveActivity/LiveActivityRegistry.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if os(iOS)
1+
#if os(iOS) && !targetEnvironment(macCatalyst)
22
import ActivityKit
33
import Foundation
44

Sources/Shared/Notifications/NotificationCommands/HandlerLiveActivity.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#if os(iOS)
1+
#if os(iOS) && !targetEnvironment(macCatalyst)
22
import ActivityKit
33
import Foundation
44
import PromiseKit

Sources/Shared/Notifications/NotificationCommands/NotificationsCommandManager.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public class NotificationCommandManager {
2222
register(command: "clear_notification", handler: HandlerClearNotification())
2323
#if os(iOS)
2424
register(command: "update_complications", handler: HandlerUpdateComplications())
25-
#if os(iOS)
25+
#if os(iOS) && !targetEnvironment(macCatalyst)
2626
if #available(iOS 17.2, *) {
2727
register(command: "live_activity", handler: HandlerStartOrUpdateLiveActivity())
2828
register(command: "end_live_activity", handler: HandlerEndLiveActivity())
@@ -111,8 +111,8 @@ private struct HandlerClearNotification: NotificationCommandHandler {
111111
// Also end any Live Activity whose tag matches — same YAML works on both iOS and Android.
112112
// Bridged into the returned Promise so the background fetch window stays open until
113113
// the activity is actually dismissed (prevents the OS suspending mid-dismiss).
114-
// ActivityKit is unavailable in the PushProvider extension, so guard accordingly.
115-
#if os(iOS)
114+
// ActivityKit is unavailable in the PushProvider extension and Mac Catalyst, so guard accordingly.
115+
#if os(iOS) && !targetEnvironment(macCatalyst)
116116
if #available(iOS 17.2, *), !Current.isAppExtension, let tag = payload["tag"] as? String {
117117
return Promise<Void> { seal in
118118
Task {

0 commit comments

Comments
 (0)