[CF-553] Post AdServices token#1534
Conversation
036ddd7 to
4e9e1ca
Compare
NachoSoto
left a comment
There was a problem hiding this comment.
Just a few minor comments!
| path = Responses; | ||
| sourceTree = "<group>"; | ||
| }; | ||
| A55D5D56282B30EF00FA7623 /* Recovered References */ = { |
There was a problem hiding this comment.
This still needs to be deleted.
| let latestNetworkIdsAndAdvertisingIdsSentByNetwork = | ||
| self.deviceCache.latestNetworkAndAdvertisingIdsSent(appUserID: currentAppUserID) | ||
| var newDictToCache = latestNetworkIdsAndAdvertisingIdsSentByNetwork | ||
| newDictToCache[String(AttributionNetwork.adServices.rawValue)] = adServicesToken | ||
| self.deviceCache.set(latestNetworkAndAdvertisingIdsSent: newDictToCache, appUserID: currentAppUserID) |
There was a problem hiding this comment.
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.
…ing (needs some cleanup but working)
…mments, rename parameter to follow dictionary naming convention
|
@NachoSoto this should be ready for re-review! i believe i addressed all your comments.. |
| request, | ||
| authHeaders: self.authHeaders | ||
| ) { (response: HTTPResponse<HTTPEmptyResponseBody>.Result) in | ||
| completion() |
There was a problem hiding this comment.
This should be called after calling the completion handler (since the operation is still technically running).
You could wrap this into a defer:
| completion() | |
| defer { | |
| completion() | |
| } |
There was a problem hiding this comment.
see andy's comment: #1534 (comment)
do we want both to be in the defer then?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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()
}There was a problem hiding this comment.
ahhh i totally misunderstood your original comment, my bad. thank you for clarifying!
| @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.") | ||
| } |
There was a problem hiding this comment.
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, *)# Conflicts: # RevenueCat.xcodeproj/project.pbxproj
|
@NachoSoto i know you already approved but just FYI i addressed comments (and replied to the one about |
Fixes [CSDK-105]. This came up in #1534 (comment) and will simplify some of the code in #1727.
Fixes [CSDK-105]. This came up in #1534 (comment) and will simplify some of the code in #1727.
* [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>
Posts the AdServices token to the backend.