Skip to content

Commit 5919a5e

Browse files
committed
Fix Notification names
1 parent e041b35 commit 5919a5e

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

Sources/AsyncLocationKit/ApplicationStateMonitor.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,13 @@
66
//
77

88
import Foundation
9-
import UIKit
9+
//#if os(iOS)
10+
//import UIKit
11+
//#elseif os(macOS)
12+
//import AppKit
13+
//#elseif os(watchOS)
14+
//import WatchKit
15+
//#endif
1016

1117
@MainActor
1218
class ApplicationStateMonitor {
@@ -88,11 +94,11 @@ class ApplicationStateMonitor {
8894

8995
private var _hasResignedActiveSequence: Any? = {
9096
guard #available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) else { return nil }
91-
return NotificationCenter.default.notifications(named: UIApplication.willResignActiveNotification).map { _ in true }
97+
return NotificationCenter.default.notifications(named: NotificationNamesConstants.willResignActiveName).map { _ in true }
9298
}()
9399

94100
private var _hasBecomeActiveSequence: Any? = {
95101
guard #available(macOS 12, iOS 15, tvOS 15, watchOS 8, *) else { return nil }
96-
return NotificationCenter.default.notifications(named: UIApplication.didBecomeActiveNotification).map { _ in true }
102+
return NotificationCenter.default.notifications(named: NotificationNamesConstants.didBecomeActiveName).map { _ in true }
97103
}()
98104
}
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// MIT License
2+
//
3+
// Copyright (c) 2022 AsyncSwift
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in all
13+
// copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
// SOFTWARE.
22+
23+
import Foundation
24+
#if os(iOS)
25+
import UIKit
26+
#elseif os(macOS)
27+
import AppKit
28+
#elseif os(watchOS)
29+
import WatchKit
30+
#endif
31+
32+
@available(macOS 12, iOS 13, tvOS 13, watchOS 8, *)
33+
struct NotificationNamesConstants {
34+
#if os(iOS)
35+
static let willResignActiveName = UIApplication.willResignActiveNotification
36+
#elseif os(macOS)
37+
static let willResignActiveName = NSApplication.willResignActiveNotification
38+
#elseif os(watchOS)
39+
static let willResignActiveName = WKExtension.applicationWillResignActiveNotification
40+
#endif
41+
42+
#if os(iOS)
43+
static let didBecomeActiveName = UIApplication.didBecomeActiveNotification
44+
#elseif os(macOS)
45+
static let didBecomeActiveName = NSApplication.didBecomeActiveNotification
46+
#elseif os(watchOS)
47+
static let didBecomeActiveName = WKExtension.applicationDidBecomeActiveNotification
48+
#endif
49+
}

Sources/AsyncLocationKit/Performers/AuthorizationPerformer.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,4 +98,3 @@ class RequestAuthorizationPerformer: AnyLocationPerformer {
9898
}
9999
}
100100
}
101-

0 commit comments

Comments
 (0)