Commit Graph
17 Commits
Author SHA1 Message Date
Antonio Pallares 05fc0a90f3 feat: disable postAttributionData requests when in UI preview mode (#4824)
* feat: disable postAttributionData requests when in UI preview mode

* tests: add unit test to check `AttributionPoster`'s new `clearPostponedAttributionData` method

* tests: add unit tests to check that `AttributionData` is never posted in UI preview mode

* refactor: simplify implementation of avoiding `AttributionPoster` requests in UI preview mode
2025-03-05 18:04:59 +01:00
NachoSoto 2bcd0ce328 5.0.0 changes: support SK2 by default 2024-07-01 14:37:21 -05:00
Cesar de la Vega bc6ccfc7c3 Remove AdClient framework related code (#3993)
We had a report of a developer that is seeing that users (who are using
iOS 18 beta) are reporting app crashes on launch with 55 unique devices
so far. They are using using iOS SDK 4.17.7.

The line that is crashing is:

```
client = clientClass.perform(#selector(FakeAfficheClient.sharedClient)).takeUnretainedValue()
```

We just couldn’t have a single variable named `adClient` without an app
getting rejected, even if it wasn’t using it at all. We built the
`AfficheClient` so prevent app rejections.

It turns out Apple has removed documentation for `AdClient`, and by
looking into
https://developer.apple.com/documentation/iad/setting-up-apple-search-ads-attribution#overview

> After February 7, 2023, all requests made to the Apple Search Ads iAd
Attribution API will return with a value of "iad-attribution" = false,
or errors. See ADClient/requestAttributionDetails(_:). Use the
AdServices framework for current attribution integration with the Apple
Search Ads Campaign Management API for devices using iOS 14.3 and later.
Attribution isn't available for downloads and redownloads from devices
using iOS 14.2 or earlier.

So this wasn't even working anyways. I removed everything related but
left the public API in place to not break anyone.
2024-06-25 23:16:14 +02:00
NachoSoto c3d00a4a74 AAAttribution.attributionToken: avoid using on main thread (#3281)
Fixes #3280.

Turns out that `AAAttribution.attributionToken()` is asynchronous, and
Apple will happily allow you to make a blocking network request on the
main thread. This avoids that.

I've refactored `AttributionFetcher.adServicesToken` to be `async` and
added `RCTestAssertNotMainThread` to ensure this doesn't break again.

The rest of the changes were necessary to accommodate the new `async`
API.
2023-10-05 23:19:59 -05:00
NachoSoto dab5035a19 visionOS: support for Xcode 15 beta 6 (#2989)
### Context:

`#if os(iOS)` no longer evaluates to `true` when compiling for
`visionOS`
Which means we need `|| os(xrOS)`.
But to support older Xcode we need `#if swift(>=5.9) && os(xrOS)`.
But, fun fact, short-circuiting doesn’t work in `Xcode 13`.
And we still need that to run iOS <15 tests (`FB12223404` /
`FB12805891`)

💩 

This works around that by defining our own `VISION_OS` flag.

### Changes:
- Added `VISION_OS` compile time flag to determine SDK
- Replaced `#if os(xrOS)` with `#if VISION_OS`
- Added flag to `Package.swift` (thanks @neonichu for helping with this)
2023-08-09 11:19:40 -07:00
Josh Holtz 375cd97bcf AdServices: Rename postAdServicesTokenIfNeeded() to postAdServicesTokenOncePerInstallIfNeeded() (#2968)
### Motivation

It was not clear what `postAdServicesTokenIfNeeded()` was doing for
anybody unfamiliar with our codebase or AdServices. This method is in
`applicationWillEnterForeground` and without digging into any of the
implementation, it looks like it could send the attribution token every
time the app enters the foreground.

The behavior was actually only sending it once per install (as it
should) so the method rename reflects that.

### Description
Renames `postAdServicesTokenIfNeeded()` to
`postAdServicesTokenOncePerInstallIfNeeded()`
2023-08-07 10:06:10 -05:00
NachoSoto a18d3b4fca PostReceiptOperation: added ability to also post AdServices token (#2566)
Cherry-picked #2549 post refactors (#2540 and #2542). This becomes a lot
simpler since #2542, thanks to the fact that we can put this new
parameter in `PurchasedTransactionData`.

### Changes:
- Added `aadAttributionToken` to `PurchasedTransactionData`
- Exposed `AttributionPoster.adServicesTokenToPostIfNeeded`
- Added snapshot test to verify it's sent
- Added `PurchasesOrchestrator` tests (SK1/SK2) for sending the
attribution token
- Added missing `PurchasesOrchestrator` tests for sending attributes
- Added log when marking `AdServices` token as synced
- Exposed `Purchases.attribution` for custom entitlement computation
framework (and added to API tester)
- Exposed `Purchases.enableAdServicesAttributionTokenCollection` for
custom entitlement computation framework (and added to API tester)
2023-05-31 10:03:55 -07:00
NachoSoto 599cfda5fb enableAdServicesAttributionTokenCollection: added integration test (#2551)
Because `AAAttribution.attributionToken()` isn't available on
simulators, we currently had no coverage for this entire part of the
codebase.
By mocking the token (on simulator + debug + integration tests only), we
can verify posting to the server works correctly.

As a follow-up, we can also verify that posting it as part of the
receipt with #2549 works correctly as well.
2023-05-26 07:18:51 -07:00
NachoSoto b00bfec8e9 AttributionPoster: replaced hardcoded strings with constants (#2548)
Just a small refactor to avoid having these magic strings duplicated
there.
2023-05-26 07:07:32 -07:00
NachoSoto 79e27f70fe Fixed AttributionFetcher.adServicesToken hanging when called in simulator (#2157) 2022-12-16 08:54:44 -08:00
SabinaHuseinova eff8e3886b Removed unnecessary Array copy (#2005) 2022-10-27 21:29:43 -07:00
NachoSoto 0bff3f65fe Sendable support (#1795)
Fixes [CSDK-379] and https://github.com/RevenueCat/purchases-ios/issues/1041#issuecomment-1206445939

[CSDK-379]: https://revenuecats.atlassian.net/browse/CSDK-379?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ

### Main changes:
- `Sendable` conformances to all types that are thread-safe
- `@unchecked Sendable` for types that the compiler can't enforce, but with documentation as to why
- Made classes that aren't mocked `final` (note that this doesn't change the API, because none of these were `open` to begin with)
- Made some classes thread-safe that weren't (like `DeviceCache`)

For the non-`final` `class`es, I've actually managed to compile the SDK with all of them as `final` and `Sendable`, to make sure that making them `@unchecked Sendable` didn't hide any other issues.

### Future improvements:
- https://twitter.com/nachosoto/status/1557139992056500224?s=21&t=arWdvEzTIFANBvwqQ0vPiA
- https://twitter.com/nachosoto/status/1557141944777592832?s=21&t=arWdvEzTIFANBvwqQ0vPiA
- https://twitter.com/nachosoto/status/1557143374922059776?s=21&t=arWdvEzTIFANBvwqQ0vPiA

### Depends on:
- #1794
- #1804
- #1806
- #1807
- #1808
- #1813
- #1822
- #1823
- #1824
- #1825
- #1826
2022-08-31 13:30:38 -07:00
NachoSoto db96bebcb6 Moved AttributionFetcherError inside AttributionFetcher (#1808)
This removes this unnecessary type in the global namespace.
Also removed 2 `cases` introduced in #1727 that aren't actually used.
2022-08-13 11:18:30 -04:00
343ba7eaf4 AdServices (#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>
2022-08-08 07:42:42 -05:00
NachoSoto 9b4b24dd18 Added tests for ReceiptFetcher.receiptData on watchOS and moved to StoreKitWorkarounds (#1640)
Fixes [CSDK-24].
Fix added in #1625.

[CSDK-24]: https://revenuecats.atlassian.net/browse/CSDK-24?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
2022-06-02 12:14:00 -07:00
NachoSoto 34cd8b4a03 Extracted CurrentUserProvider protocol to simplify dependency injection (#1462)
A lot of our classes depended on the mutable `IdentityManager`, when in reality they only needed a read-only `currentAppUserID`.
This PR changes the requirement, with the following advantages:

- Ensure all these classes (`AttributionPoster`, `PurchasesOrchestrator`, `TrialOrIntroPriceEligibiltyChecker`, `BeginRefundRequestHelper`, `ManageSubscriptionsHelper`) cannot logIn / logOut, only read the current user
- Simplify tests by only requiring a smaller type
- Simplifying instantiation of these types outside the normal `Purchases` initialization.

I've also created `MockCurrentUserProvider`, but changed the existing `MockIdentityManager` so that calls to `logIn`/`logOut` just fail. These aren't mocked, and they wouldn't have an impact on the mocked readable values, so calling them is most likely unexpected and should make the test fail.
2022-04-08 15:39:34 -07:00
aboedo f5697de730 renamed Purchases folder to Sources (#1416)
* renamed `Purchases` folder to `Sources`

* temporarily enabling installation test jobs

* re-disabling installation test jobs
2022-03-28 11:53:24 -03:00