Skip to content

Commit

Permalink
Check iOS 13 is available at runtime (#21)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcaunt authored Nov 5, 2024
1 parent 0a1e93f commit a293877
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 7 deletions.
2 changes: 1 addition & 1 deletion Sources/UID2GMAPlugin/AdvertisingTokenNotFoundError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import Foundation

/// Advertising Token Not Found for GMA Adapter
@objc(UID2GMAAdvertisingTokenNotFoundError)
public class AdvertisingTokenNotFoundError: NSError {
public class AdvertisingTokenNotFoundError: NSError, @unchecked Sendable {

convenience init() {
self.init(domain: "UID", code: 1)
Expand Down
11 changes: 9 additions & 2 deletions Sources/UID2GMAPlugin/EUIDGMAMediationAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,21 @@ class EUIDGMAMediationAdapter: NSObject {
extension EUIDGMAMediationAdapter: GADRTBAdapter {

static func setUpWith(_ configuration: GADMediationServerConfiguration, completionHandler: @escaping GADMediationAdapterSetUpCompletionBlock) {

guard isOperatingSystemSupported else {
completionHandler(OperatingSystemUnsupportedError())
return
}
// Ensure UID2Manager has started
_ = EUIDManager.shared

completionHandler(nil)
}

func collectSignals(for params: GADRTBRequestParameters, completionHandler: @escaping GADRTBSignalCompletionHandler) {
guard isOperatingSystemSupported else {
completionHandler(nil, OperatingSystemUnsupportedError())
return
}
Task {
guard let advertisingToken = await EUIDManager.shared.getAdvertisingToken() else {
completionHandler(nil, AdvertisingTokenNotFoundError())
Expand All @@ -41,7 +48,7 @@ extension EUIDGMAMediationAdapter: GADRTBAdapter {
var version = GADVersionNumber()
version.majorVersion = 1
version.minorVersion = 0
version.patchVersion = 0
version.patchVersion = 1
return version
}

Expand Down
24 changes: 24 additions & 0 deletions Sources/UID2GMAPlugin/OperatingSystemSupport.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//
// OperatingSystemUnsupportedError.swift
//

import Foundation

/// Adapter implementations in this package are called at runtime, ignoring @available attributes.
/// By checking the operating system version we can avoid calling UID code which is unavailable.
let isOperatingSystemSupported = ProcessInfo.processInfo.isOperatingSystemAtLeast(
.init(
majorVersion: 13,
minorVersion: 0,
patchVersion: 0
)
)

/// Adapter called on an unsupported operating system version i.e. lower than UID2's deployment target.
@objc(UID2GMAOperatingSystemUnsupported)
public final class OperatingSystemUnsupportedError: NSError, @unchecked Sendable {

convenience init() {
self.init(domain: "UID", code: 2)
}
}
11 changes: 9 additions & 2 deletions Sources/UID2GMAPlugin/UID2GMAMediationAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,21 @@ class UID2GMAMediationAdapter: NSObject {
extension UID2GMAMediationAdapter: GADRTBAdapter {

static func setUpWith(_ configuration: GADMediationServerConfiguration, completionHandler: @escaping GADMediationAdapterSetUpCompletionBlock) {

guard isOperatingSystemSupported else {
completionHandler(OperatingSystemUnsupportedError())
return
}
// Ensure UID2Manager has started
_ = UID2Manager.shared

completionHandler(nil)
}

func collectSignals(for params: GADRTBRequestParameters, completionHandler: @escaping GADRTBSignalCompletionHandler) {
guard isOperatingSystemSupported else {
completionHandler(nil, OperatingSystemUnsupportedError())
return
}
Task {
guard let advertisingToken = await UID2Manager.shared.getAdvertisingToken() else {
completionHandler(nil, AdvertisingTokenNotFoundError())
Expand All @@ -44,7 +51,7 @@ extension UID2GMAMediationAdapter: GADRTBAdapter {
var version = GADVersionNumber()
version.majorVersion = 1
version.minorVersion = 0
version.patchVersion = 0
version.patchVersion = 1
return version
}

Expand Down
4 changes: 2 additions & 2 deletions UID2GMAPlugin.podspec.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
"summary": "A plugin for integrating UID2 and Google GMA into iOS applications.",
"homepage": "https://unifiedid.com/",
"license": "Apache License, Version 2.0",
"version": "1.0.0",
"version": "1.0.1",
"authors": {
"David Snabel-Caunt": "[email protected]"
},
"source": {
"git": "https://github.com/IABTechLab/uid2-ios-plugin-google-gma.git",
"tag": "v1.0.0"
"tag": "v1.0.1"
},
"platforms": {
"ios": "12.0"
Expand Down

0 comments on commit a293877

Please sign in to comment.