Skip to content

Commit 01dfd42

Browse files
authored
Check iOS 13 is available at runtime (#21)
1 parent 6170817 commit 01dfd42

File tree

5 files changed

+40
-7
lines changed

5 files changed

+40
-7
lines changed

Sources/UID2IMAPlugin/AdvertisingTokenNotFoundError.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import Foundation
99

1010
/// Advertising Token Not Found for IMA Adapter
1111
@objc(UID2IMAAdvertisingTokenNotFoundError)
12-
public class AdvertisingTokenNotFoundError: NSError {
12+
public class AdvertisingTokenNotFoundError: NSError, @unchecked Sendable {
1313

1414
convenience init() {
1515
self.init(domain: "UID", code: 1)

Sources/UID2IMAPlugin/EUIDIMASecureSignalsAdapter.swift

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ import UID2
1111
public class EUIDIMASecureSignalsAdapter: NSObject {
1212

1313
required public override init() {
14+
guard isOperatingSystemSupported else {
15+
return
16+
}
1417
// Ensure UID2Manager has started
1518
_ = EUIDManager.shared
1619
}
@@ -24,7 +27,7 @@ extension EUIDIMASecureSignalsAdapter: IMASecureSignalsAdapter {
2427
let version = IMAVersion()
2528
version.majorVersion = 1
2629
version.minorVersion = 0
27-
version.patchVersion = 0
30+
version.patchVersion = 1
2831
return version
2932
}
3033

@@ -38,6 +41,10 @@ extension EUIDIMASecureSignalsAdapter: IMASecureSignalsAdapter {
3841
}
3942

4043
public func collectSignals(completion: @escaping IMASignalCompletionHandler) {
44+
guard isOperatingSystemSupported else {
45+
completion(nil, OperatingSystemUnsupportedError())
46+
return
47+
}
4148
Task {
4249
guard let advertisingToken = await EUIDManager.shared.getAdvertisingToken() else {
4350
completion(nil, AdvertisingTokenNotFoundError())
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import Foundation
2+
3+
/// Adapter implementations in this package are called at runtime, ignoring @available attributes.
4+
/// By checking the operating system version we can avoid calling UID code which is unavailable.
5+
let isOperatingSystemSupported = ProcessInfo.processInfo.isOperatingSystemAtLeast(
6+
.init(
7+
majorVersion: 13,
8+
minorVersion: 0,
9+
patchVersion: 0
10+
)
11+
)
12+
13+
/// Adapter called on an unsupported operating system version i.e. lower than UID2's deployment target.
14+
@objc(UID2GMAOperatingSystemUnsupported)
15+
public final class OperatingSystemUnsupportedError: NSError, @unchecked Sendable {
16+
17+
convenience init() {
18+
self.init(domain: "UID", code: 2)
19+
}
20+
}

Sources/UID2IMAPlugin/UID2IMASecureSignalsAdapter.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,11 @@ import UID2
1212
@available(iOS 13.0, *)
1313
@objc(UID2IMASecureSignalsAdapter)
1414
public class UID2IMASecureSignalsAdapter: NSObject {
15-
15+
1616
required public override init() {
17+
guard isOperatingSystemSupported else {
18+
return
19+
}
1720
// Ensure UID2Manager has started
1821
_ = UID2Manager.shared
1922
}
@@ -27,7 +30,7 @@ extension UID2IMASecureSignalsAdapter: IMASecureSignalsAdapter {
2730
let version = IMAVersion()
2831
version.majorVersion = 1
2932
version.minorVersion = 0
30-
version.patchVersion = 0
33+
version.patchVersion = 1
3134
return version
3235
}
3336

@@ -41,7 +44,10 @@ extension UID2IMASecureSignalsAdapter: IMASecureSignalsAdapter {
4144
}
4245

4346
public func collectSignals(completion: @escaping IMASignalCompletionHandler) {
44-
47+
guard isOperatingSystemSupported else {
48+
completion(nil, OperatingSystemUnsupportedError())
49+
return
50+
}
4551
Task {
4652
guard let advertisingToken = await UID2Manager.shared.getAdvertisingToken() else {
4753
completion(nil, AdvertisingTokenNotFoundError())

UID2IMAPlugin.podspec.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
"summary": "A plugin for integrating UID2 and Google IMA into iOS applications.",
44
"homepage": "https://unifiedid.com/",
55
"license": "Apache License, Version 2.0",
6-
"version": "1.0.0",
6+
"version": "1.0.1",
77
"authors": {
88
"David Snabel-Caunt": "[email protected]"
99
},
1010
"source": {
1111
"git": "https://github.com/IABTechLab/uid2-ios-plugin-google-ima.git",
12-
"tag": "v1.0.0"
12+
"tag": "v1.0.1"
1313
},
1414
"platforms": {
1515
"ios": "12.0"

0 commit comments

Comments
 (0)