Skip to content

[CF-553] Post AdServices token#1534

Merged
beylmk merged 95 commits into
ad-services-sdkfrom
ad-services-post
Jun 9, 2022
Merged

[CF-553] Post AdServices token#1534
beylmk merged 95 commits into
ad-services-sdkfrom
ad-services-post

Conversation

@beylmk

@beylmk beylmk commented Apr 26, 2022

Copy link
Copy Markdown
Contributor

Posts the AdServices token to the backend.

Maddie Beyl and others added 28 commits April 20, 2022 10:15
…ction, deprecated automaticAppleSearchAdsAttributionCollection
Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>
# Conflicts:
#	Sources/Attribution/AttributionPoster.swift
@beylmk beylmk force-pushed the ad-services-post branch from 036ddd7 to 4e9e1ca Compare April 26, 2022 14:45

@NachoSoto NachoSoto left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few minor comments!

Comment thread RevenueCat.xcodeproj/project.pbxproj Outdated
path = Responses;
sourceTree = "<group>";
};
A55D5D56282B30EF00FA7623 /* Recovered References */ = {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This still needs to be deleted.

Comment thread Sources/Attribution/AttributionPoster.swift Outdated
Comment on lines +119 to +123
let latestNetworkIdsAndAdvertisingIdsSentByNetwork =
self.deviceCache.latestNetworkAndAdvertisingIdsSent(appUserID: currentAppUserID)
var newDictToCache = latestNetworkIdsAndAdvertisingIdsSentByNetwork
newDictToCache[String(AttributionNetwork.adServices.rawValue)] = adServicesToken
self.deviceCache.set(latestNetworkAndAdvertisingIdsSent: newDictToCache, appUserID: currentAppUserID)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not for this PR, but this get-set can introduce a race condition. We'd have to use an API like Atomic.write that takes the inout and writes it inside of the lock.

Comment thread Sources/Attribution/AttributionPoster.swift Outdated
Comment thread Tests/UnitTests/Mocks/MockBackend.swift Outdated
Comment thread Tests/UnitTests/Mocks/MockDeviceCache.swift Outdated
Comment thread Tests/UnitTests/Purchasing/PurchasesTests.swift Outdated
@beylmk beylmk force-pushed the ad-services-post branch from 51dd7b6 to f6ad61d Compare June 6, 2022 20:59
@beylmk beylmk force-pushed the ad-services-post branch from f6ad61d to 7fcb1c1 Compare June 6, 2022 21:04
@beylmk

beylmk commented Jun 7, 2022

Copy link
Copy Markdown
Contributor Author

@NachoSoto this should be ready for re-review! i believe i addressed all your comments..

@NachoSoto NachoSoto left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

Comment thread Sources/Attribution/AttributionPoster.swift Outdated
Comment thread Sources/Caching/DeviceCache.swift
request,
authHeaders: self.authHeaders
) { (response: HTTPResponse<HTTPEmptyResponseBody>.Result) in
completion()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be called after calling the completion handler (since the operation is still technically running).
You could wrap this into a defer:

Suggested change
completion()
defer {
completion()
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see andy's comment: #1534 (comment)

do we want both to be in the defer then?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understand the comment, the completion here has to be called for both cases, and the response handler as well. My comment was regarding the fact that the operation shouldn't complete until we've called the completion handler.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@aboedo 👀 ^^

@aboedo aboedo Jun 9, 2022

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think both suggestions are compatible - like Nacho said, we should call completion as the last step in the method, and what I suggested was to do it by having both this code path and the early return look similar, i.e.:

guard let appUserID = try? self.configuration.appUserID.escapedOrError() else {
    defer { completion() } 
    self.responseHandler?(.missingAppUserID())
}

/// ...

{ (response: HTTPResponse<HTTPEmptyResponseBody>.Result) in
    defer { completion() } 
    self.responseHandler?(response.error.map(BackendError.networkError))
}

or

guard let appUserID = try? self.configuration.appUserID.escapedOrError() else {
    self.responseHandler?(.missingAppUserID())
    completion()
}

/// ...

{ (response: HTTPResponse<HTTPEmptyResponseBody>.Result) in
    self.responseHandler?(response.error.map(BackendError.networkError))
    completion()
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhh i totally misunderstood your original comment, my bad. thank you for clarifying!

Comment on lines +128 to +132
@available(iOS 14.3, macOS 11.1, macCatalyst 14.3, *)
func testPostAdServicesTokenIfNeededSkipsIfAlreadySent() throws {
guard #available(iOS 14.3, macOS 11.1, macCatalyst 14.3, *) else {
throw XCTSkip("Required API is not available for this test.")
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 3 are duplicated in all of these tests.
Just a suggestion, feel free to ignore, but you could extract a BaseAttributionPosterTests that has the properties and setUp in this class that AttributionPosterTests and a new AdServicesAttributionPosterTests class can inherit.
Then you can put this inside of a shared setUp as well as making that whole class:

@available(iOS 14.3, macOS 11.1, macCatalyst 14.3, *)

Comment thread Tests/UnitTests/Mocks/MockAttributionFetcher.swift Outdated
Comment thread Tests/UnitTests/Mocks/MockDeviceCache.swift Outdated
Comment thread Tests/UnitTests/Purchasing/PurchasesTests.swift Outdated
Comment thread Tests/UnitTests/Attribution/AttributionPosterTests.swift Outdated
@beylmk beylmk force-pushed the ad-services-post branch from 26cb969 to bdca17a Compare June 8, 2022 17:26
@beylmk

beylmk commented Jun 8, 2022

Copy link
Copy Markdown
Contributor Author

@NachoSoto i know you already approved but just FYI i addressed comments (and replied to the one about defer)

Comment thread Tests/UnitTests/Attribution/AttributionPosterTests.swift Outdated
@beylmk beylmk merged commit cbe9819 into ad-services-sdk Jun 9, 2022
@beylmk beylmk deleted the ad-services-post branch June 9, 2022 23:38
NachoSoto added a commit that referenced this pull request Jun 23, 2022
Fixes [CSDK-105].

This came up in #1534 (comment) and will simplify some of the code in #1727.
NachoSoto added a commit that referenced this pull request Jun 27, 2022
Fixes [CSDK-105].

This came up in #1534 (comment) and will simplify some of the code in #1727.
joshdholtz added a commit that referenced this pull request Aug 8, 2022
* [CF-106] Fetch AdServices Token (#1519)

Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>
Co-authored-by: Josh Holtz <me@joshholtz.com>

* [CF-553] Post AdServices token (#1534)

Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>
Co-authored-by: Josh Holtz <me@joshholtz.com>

* Update ios 14 snapshots tets

* Reworked adservices to use new Purchases.shared.attribution API

* Updated with some comments from PR

* Add iAd code back (#1739)

Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>

* use new mapKeys dictionary extension for device cache

* update for some pr comments

* remove purchasestests

* generate missing snapshots

* fix deprecation messages to clarify method now called on shared instance

* Fix for inserting nonstring into userdefaults

* Add tests for bug

* fix lint

* Added availablility checks for tests and removed unused varialbes

* Whoops... wrong class

Co-authored-by: beylmk <maddie@revenuecat.com>
Co-authored-by: NachoSoto <NachoSoto@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants