Skip to content

Commit a0f9fc7

Browse files
authored
Swift 6 support (#713)
1 parent ed0c2e5 commit a0f9fc7

File tree

4 files changed

+42
-36
lines changed

4 files changed

+42
-36
lines changed

ios/AirshipPluginLoader.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import AirshipFrameworkProxy
44

55
@objc(AirshipPluginLoader)
6+
@MainActor
67
public class AirshipPluginLoader: NSObject, AirshipPluginLoaderProtocol {
78
@objc
89
public static var disabled: Bool = false
10+
911
public static func onLoad() {
1012
if (!disabled) {
1113
AirshipReactNative.shared.onLoad()

ios/AirshipReactNative.swift

Lines changed: 37 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import AirshipFrameworkProxy
66
import React
77

88
@objc
9-
public class AirshipReactNative: NSObject {
10-
9+
public final class AirshipReactNative: NSObject, Sendable {
10+
1111
@objc
1212
public static let pendingEventsEventName = "com.airship.pending_events"
1313

@@ -18,19 +18,16 @@ public class AirshipReactNative: NSObject {
1818
public static let pendingEmbeddedUpdated = "com.airship.iax.pending_embedded_updated"
1919

2020
private let serialQueue = AirshipAsyncSerialQueue()
21-
var lock = AirshipLock()
22-
var pendingPresentationRequests: [String: PresentationOptionsOverridesRequest] = [:]
23-
21+
private let _pendingPresentationRequests = AirshipAtomicValue<[String: PresentationOptionsOverridesRequest]>([:])
22+
private let _overridePresentationOptionsEnabled = AirshipAtomicValue<Bool>(false)
23+
2424
@objc
25-
public var overridePresentationOptionsEnabled: Bool = false {
26-
didSet {
27-
if (!overridePresentationOptionsEnabled) {
28-
lock.sync {
29-
self.pendingPresentationRequests.values.forEach { request in
30-
request.result(options: nil)
31-
}
32-
self.pendingPresentationRequests.removeAll()
33-
}
25+
public var overridePresentationOptionsEnabled: Bool {
26+
get { _overridePresentationOptionsEnabled.value }
27+
set {
28+
_overridePresentationOptionsEnabled.value = newValue
29+
if (!newValue) {
30+
self.clearPendingPresentationRequests()
3431
}
3532
}
3633
}
@@ -48,10 +45,11 @@ public class AirshipReactNative: NSObject {
4845

4946
@objc
5047
public func setNotifier(_ notifier: ((String, [String: Any]) -> Void)?) {
48+
let wrappedNotifier = AirshipUnsafeSendableWrapper(notifier)
5149
self.serialQueue.enqueue { @MainActor in
52-
if let notifier = notifier {
50+
if wrappedNotifier.value != nil {
5351
await self.eventNotifier.setNotifier {
54-
notifier(AirshipReactNative.pendingEventsEventName, [:])
52+
wrappedNotifier.value?(AirshipReactNative.pendingEventsEventName, [:])
5553
}
5654

5755
if AirshipProxyEventEmitter.shared.hasAnyEvents() {
@@ -76,10 +74,13 @@ public class AirshipReactNative: NSObject {
7674
}
7775

7876
let requestID = UUID().uuidString
79-
self.lock.sync {
80-
self.pendingPresentationRequests[requestID] = request
77+
self._pendingPresentationRequests.update {
78+
var requests = $0
79+
requests[requestID] = request
80+
return requests
8181
}
82-
notifier(
82+
83+
wrappedNotifier.value?(
8384
AirshipReactNative.overridePresentationOptionsEventName,
8485
[
8586
"pushPayload": requestPayload,
@@ -90,25 +91,29 @@ public class AirshipReactNative: NSObject {
9091
} else {
9192
await self.eventNotifier.setNotifier(nil)
9293
AirshipProxy.shared.push.presentationOptionOverrides = nil
93-
94-
self.lock.sync {
95-
self.pendingPresentationRequests.values.forEach { request in
96-
request.result(options: nil)
97-
}
98-
self.pendingPresentationRequests.removeAll()
99-
}
94+
self.clearPendingPresentationRequests()
10095
}
10196
}
10297
}
10398

10499
@objc
105100
public func presentationOptionOverridesResult(requestID: String, presentationOptions: [String]?) {
106-
lock.sync {
107-
pendingPresentationRequests[requestID]?.result(optionNames: presentationOptions)
108-
pendingPresentationRequests[requestID] = nil
101+
_pendingPresentationRequests.update {
102+
var requests = $0
103+
requests[requestID]?.result(optionNames: presentationOptions)
104+
requests[requestID] = nil
105+
return requests
106+
}
107+
}
108+
109+
private func clearPendingPresentationRequests() {
110+
_pendingPresentationRequests.update { requests in
111+
requests.values.forEach { request in
112+
request.result(options: nil)
113+
}
114+
return [:]
109115
}
110116
}
111-
112117

113118
@MainActor
114119
func onLoad() {
@@ -767,8 +772,8 @@ extension AirshipReactNative: AirshipProxyDelegate {
767772

768773

769774
private actor EventNotifier {
770-
private var notifier: (() -> Void)?
771-
func setNotifier(_ notifier: (() -> Void)?) {
775+
private var notifier: (@Sendable () -> Void)?
776+
func setNotifier(_ notifier: (@Sendable () -> Void)?) {
772777
self.notifier = notifier
773778
}
774779

ios/MessageWebViewWrapper.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ public protocol MessageWebViewWrapperDelegate {
1616
}
1717

1818
@objc(RNAirshipMessageWebViewWrapper)
19+
@MainActor
1920
public class MessageWebViewWrapper: NSObject {
2021
private let innerWrapper: _MessageWebViewWrapper
2122

@@ -36,7 +37,6 @@ public class MessageWebViewWrapper: NSObject {
3637
}
3738
}
3839

39-
@MainActor
4040
@objc
4141
public func loadMessage(messageID: String?) {
4242
self.innerWrapper.loadMessage(messageID: messageID)
@@ -49,7 +49,7 @@ public class MessageWebViewWrapper: NSObject {
4949
}
5050

5151

52-
class _MessageWebViewWrapper: NSObject, AirshipWKNavigationDelegate, NativeBridgeDelegate {
52+
class _MessageWebViewWrapper: NSObject, AirshipWKNavigationDelegate, @preconcurrency NativeBridgeDelegate {
5353

5454
public weak var delegate: MessageWebViewWrapperDelegate? = nil
5555

@@ -93,8 +93,6 @@ class _MessageWebViewWrapper: NSObject, AirshipWKNavigationDelegate, NativeBridg
9393
}
9494
}
9595

96-
97-
9896
@MainActor
9997
private func startLoad(messageID: String) async {
10098
var message: MessageCenterMessage? = nil

react-native-airship.podspec

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Pod::Spec.new do |s|
1616
s.source_files = "ios/**/*.{h,m,mm,swift,cpp}"
1717
s.exclude_files = "ios/generated/**/*"
1818
s.private_header_files = "ios/**/*.h"
19+
s.swift_version = "6.0"
1920

2021
install_modules_dependencies(s)
2122

0 commit comments

Comments
 (0)