Skip to content

Commit

Permalink
EUID Support (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
dcaunt authored Sep 9, 2024
1 parent 03095c0 commit 6170817
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>UID2EnvironmentEUID</key>
<false/>
<key>UIMainStoryboardFile~ipad</key>
<string>iPad</string>
<key>UIMainStoryboardFile</key>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,16 @@ class ViewController: UIViewController, IMAAdsLoaderDelegate, IMAAdsManagerDeleg
private var contentPlayhead: IMAAVPlayerContentPlayhead?
private let adsLoader = IMAAdsLoader(settings: nil)
private var adsManager: IMAAdsManager?


private let manager: UID2Manager = {
let isEUID = Bundle.main.object(forInfoDictionaryKey: "UID2EnvironmentEUID") as? Bool ?? false
if isEUID {
return EUIDManager.shared
} else {
return UID2Manager.shared
}
}()

// MARK: - View controller lifecycle methods

override func viewDidLoad() {
Expand Down Expand Up @@ -69,7 +78,7 @@ class ViewController: UIViewController, IMAAdsLoaderDelegate, IMAAdsManagerDeleg
refreshResponseKey: uid2IdentityFromFile.refreshResponseKey)

Task {
await UID2Manager.shared.setIdentity(uid2Identity)
await manager.setIdentity(uid2Identity)
}
} catch {
print("Error loading UID2Identity")
Expand Down
2 changes: 2 additions & 0 deletions RELEASE_PROCESS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Version Numbering follows [Semantic Versioning](https://semver.org) standards.
*https://github.com/IABTechLab/uid2-ios-plugin-google-ima/blob/ac286e2c9241c04c001ff7a42a4cbb1dfc2c80b9/Package.swift#L18
* Update / Confirm `adapterVersion()` in `UID2IMASecureSignalsAdapter.swift` is set to expected version
* https://github.com/IABTechLab/uid2-ios-plugin-google-ima/blob/ac286e2c9241c04c001ff7a42a4cbb1dfc2c80b9/Sources/UID2IMAPlugin/UID2IMASecureSignalsAdapter.swift#L24-L30
* Update / Confirm `adapterVersion()` in `EUIDIMASecureSignalsAdapter.swift` is set to expected version
* https://github.com/IABTechLab/uid2-ios-plugin-google-ima/blob/d5278ce634aa228712d9a6dae032232df7f2a434/Sources/UID2IMAPlugin/EUIDIMASecureSignalsAdapter.swift#L22-L28
* Update / Confirm `version` and `source.tag` in `UID2IMAPlugin.podspec.json` are set to expected version
* https://github.com/IABTechLab/uid2-ios-plugin-google-ima/blob/main/UID2IMAPlugin.podspec.jsonL6-L12
* Add and / or Edit any ADRs that support this release
Expand Down
49 changes: 49 additions & 0 deletions Sources/UID2IMAPlugin/EUIDIMASecureSignalsAdapter.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
//
// EUIDIMASecureSignalsAdapter.swift
//

import Foundation
import GoogleInteractiveMediaAds
import UID2

@available(iOS 13.0, *)
@objc(EUIDIMASecureSignalsAdapter)
public class EUIDIMASecureSignalsAdapter: NSObject {

required public override init() {
// Ensure UID2Manager has started
_ = EUIDManager.shared
}

}

@available(iOS 13, *)
extension EUIDIMASecureSignalsAdapter: IMASecureSignalsAdapter {

public static func adapterVersion() -> IMAVersion {
let version = IMAVersion()
version.majorVersion = 1
version.minorVersion = 0
version.patchVersion = 0
return version
}

public static func adSDKVersion() -> IMAVersion {
let sdkVersion = UID2SDKProperties.getUID2SDKVersion()
let version = IMAVersion()
version.majorVersion = sdkVersion.major
version.minorVersion = sdkVersion.minor
version.patchVersion = sdkVersion.patch
return version
}

public func collectSignals(completion: @escaping IMASignalCompletionHandler) {
Task {
guard let advertisingToken = await EUIDManager.shared.getAdvertisingToken() else {
completion(nil, AdvertisingTokenNotFoundError())
return
}
completion(advertisingToken, nil)
}
}
}
11 changes: 6 additions & 5 deletions Sources/UID2IMAPlugin/UID2IMASecureSignalsAdapter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ extension UID2IMASecureSignalsAdapter: IMASecureSignalsAdapter {

public static func adapterVersion() -> IMAVersion {
let version = IMAVersion()
version.majorVersion = 0
version.minorVersion = 4
version.majorVersion = 1
version.minorVersion = 0
version.patchVersion = 0
return version
}

public static func adSDKVersion() -> IMAVersion {
let sdkVersion = UID2SDKProperties.getUID2SDKVersion()
let version = IMAVersion()
version.majorVersion = UID2SDKProperties.getUID2SDKVersion().major
version.minorVersion = UID2SDKProperties.getUID2SDKVersion().minor
version.patchVersion = UID2SDKProperties.getUID2SDKVersion().patch
version.majorVersion = sdkVersion.major
version.minorVersion = sdkVersion.minor
version.patchVersion = sdkVersion.patch
return version
}

Expand Down
78 changes: 78 additions & 0 deletions Tests/UID2IMAPluginTests/EUIDIMASecureSignalsAdapterTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
//
// EUIDIMASecureSignalsAdapterTests.swift
//

import XCTest
import GoogleInteractiveMediaAds
import UID2
import UID2IMAPlugin

final class EUIDIMASecureSignalsAdapterTests: XCTestCase {
/// 🟩 - IMA Adapter Request Signal Success
func testRequestSignalsSuccess() async throws {
// Seed the sample UID2Identity data in the UID2Manager
await EUIDManager.shared.setAutomaticRefreshEnabled(false)
await EUIDManager.shared.setIdentity(
UID2Identity(
advertisingToken: "euid-test-token",
refreshToken: "refresh-token",
identityExpires: Date(timeIntervalSinceNow: 60 * 60).millisecondsSince1970,
refreshFrom: Date(timeIntervalSinceNow: 60 * 40).millisecondsSince1970,
refreshExpires: Date(timeIntervalSinceNow: 60 * 50).millisecondsSince1970,
refreshResponseKey: ""
)
)

let signal = try await EUIDIMASecureSignalsAdapter().collectSignals()

// Confirm that Adapter returns expected data
XCTAssertEqual("euid-test-token", signal)
}

/// 🟥 - GMA Adapter Request Signal Error No Identity
func testRequestSignalsNoIdentity() async throws {
// Ensure no identity is set
await EUIDManager.shared.resetIdentity()

let result = await Task<String?, Error> {
try await EUIDIMASecureSignalsAdapter().collectSignals()
}.result
XCTAssertThrowsError(try result.get()) { error in
let adapterError = error as? AdvertisingTokenNotFoundError
XCTAssertEqual(AdvertisingTokenNotFoundError(), adapterError)
}
}

/// 🟥 - IMA Adapter Request Signal No Advertising Token Error
func testRequestSignalsNoAdvertisingToken() async throws {
// Set an identity with an invalid advertisingToken
await EUIDManager.shared.setAutomaticRefreshEnabled(false)
await EUIDManager.shared.setIdentity(
UID2Identity(
advertisingToken: "",
refreshToken: "refresh-token",
identityExpires: Date(timeIntervalSinceNow: 60 * 60).millisecondsSince1970,
refreshFrom: Date(timeIntervalSinceNow: 60 * 40).millisecondsSince1970,
refreshExpires: Date(timeIntervalSinceNow: 60 * 50).millisecondsSince1970,
refreshResponseKey: ""
)
)

let result = await Task<String?, Error> {
try await EUIDIMASecureSignalsAdapter().collectSignals()
}.result
XCTAssertThrowsError(try result.get()) { error in
let adapterError = error as? AdvertisingTokenNotFoundError
XCTAssertEqual(AdvertisingTokenNotFoundError(), adapterError)
}
}

func testAdSDKVersion() async throws {
let adSDKVersion = EUIDIMASecureSignalsAdapter.adSDKVersion()
let sdkVersion = await EUIDManager.shared.sdkVersion

XCTAssertEqual(sdkVersion.major, adSDKVersion.majorVersion)
XCTAssertEqual(sdkVersion.minor, adSDKVersion.minorVersion)
XCTAssertEqual(sdkVersion.patch, adSDKVersion.patchVersion)
}
}
4 changes: 2 additions & 2 deletions UID2IMAPlugin.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 IMA into iOS applications.",
"homepage": "https://unifiedid.com/",
"license": "Apache License, Version 2.0",
"version": "0.4.0",
"version": "1.0.0",
"authors": {
"David Snabel-Caunt": "[email protected]"
},
"source": {
"git": "https://github.com/IABTechLab/uid2-ios-plugin-google-ima.git",
"tag": "v0.4.0"
"tag": "v1.0.0"
},
"platforms": {
"ios": "12.0"
Expand Down

0 comments on commit 6170817

Please sign in to comment.