Skip to content

Commit

Permalink
Merge branch 'ad-services-sdk' into ad-services
Browse files Browse the repository at this point in the history
  • Loading branch information
Maddie Beyl committed Apr 27, 2022
2 parents 67b3e7a + 2ceaefd commit 5268820
Show file tree
Hide file tree
Showing 32 changed files with 426 additions and 181 deletions.
39 changes: 22 additions & 17 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,17 @@ jobs:
steps:
- checkout
- install-dependencies
- install-and-create-sim:
install-name: iOS 15.2 Simulator
sim-device-type: iPhone-13
sim-device-runtime: iOS-15-2
sim-name: iPhone 13 (15.2)
- run:
name: Run tests
command: bundle exec fastlane test_ios
no_output_timeout: 30m
environment:
SCAN_DEVICE: iPhone 12 (15.4)
SCAN_DEVICE: iPhone 13 (15.2)
- store_test_results:
path: fastlane/test_output
- store_artifacts:
Expand Down Expand Up @@ -433,50 +438,50 @@ workflows:
build-test:
jobs:
- lint:
xcode_version: '13.3.0'
xcode_version: '13.3.1'
- run-test-ios-15:
xcode_version: '13.3.0'
xcode_version: '13.3.1'
- run-test-tvos:
xcode_version: '13.3.0'
xcode_version: '13.3.1'
- run-test-ios-14:
xcode_version: '13.3.0'
xcode_version: '13.3.1'
- run-test-ios-13:
xcode_version: '13.3.0'
xcode_version: '13.3.1'
<<: *release-branches-and-main
- run-test-ios-12:
xcode_version: '13.3.0'
xcode_version: '13.3.1'
<<: *release-branches-and-main
- build-tv-watch-and-macos:
xcode_version: '13.3.0'
xcode_version: '13.3.1'
- release-checks:
xcode_version: '13.3.0'
xcode_version: '13.3.1'
<<: *release-branches
- backend-integration-tests:
xcode_version: '13.3.0'
xcode_version: '13.3.1'
filters:
branches:
# Forked pull requests have CIRCLE_BRANCH set to pull/XXX
ignore: /pull\/[0-9]+/
- installation-tests-cocoapods:
xcode_version: '13.3.0'
xcode_version: '13.3.1'
<<: *release-tags-and-branches
- installation-tests-swift-package-manager:
xcode_version: '13.3.0'
xcode_version: '13.3.1'
<<: *release-tags-and-branches
- installation-tests-carthage:
xcode_version: '13.3.0'
xcode_version: '13.3.1'
<<: *release-tags-and-branches
- installation-tests-xcode-direct-integration:
xcode_version: '13.3.0'
xcode_version: '13.3.1'
<<: *release-tags-and-branches
deploy:
jobs:
- make-release:
xcode_version: '13.3.0'
xcode_version: '13.3.1'
<<: *release-tags
- prepare-next-version:
xcode_version: '13.3.0'
xcode_version: '13.3.1'
<<: *release-tags
- docs-deploy:
xcode_version: '13.3.0'
xcode_version: '13.3.1'
<<: *release-tags
4 changes: 2 additions & 2 deletions .jazzy.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ clean: true
author: RevenueCat
author_url: https://revenuecat.com
sdk: iphonesimulator
module_version: 4.3.0-SNAPSHOT
module_version: 4.4.0-SNAPSHOT
github_url: https://github.com/revenuecat/purchases-ios
github_file_prefix: https://github.com/revenuecat/purchases-ios/tree/4.3.0-SNAPSHOT
github_file_prefix: https://github.com/revenuecat/purchases-ios/tree/4.4.0-SNAPSHOT
output: generated_docs
include:
- "Sources/**/*"
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.3.0-SNAPSHOT
4.4.0-SNAPSHOT
29 changes: 10 additions & 19 deletions CHANGELOG.latest.md
Original file line number Diff line number Diff line change
@@ -1,26 +1,17 @@
### Version 4.2.1 changes:

- Fixed a potential race condition when syncing user attributes #1479

### Version 4.2.0 changes:
## 4.3.0

#### API updates:

- Added new method `setMixpanelDistinctID` as a convenience method for setting the required attribute for the Mixpanel integration #1397

- `getPromotionalOffer` has been deprecated in favor of `promotionalOffer` #1405

- `getEligiblePromotionalOffers` has been deprecated in favor of `eligiblePromotionalOffers` #1405

- `StoreProductDiscount` now includes the `numberOfPeriods` property #1428

- Introduced new `Storefront` type to abstract SK1's `SKStorefront` and SK2's `StoreKit.Storefront`.
- Exposed `Storefront.currentStorefront`.
- Added new `ErrorCode.offlineConnectionError` to differenciate offline errors versus the more generic `.networkError`.
- Added `Purchases-setFirebaseAppInstanceID` to allow associating RevenueCat users with Firebase.
- Added `Purchases.setPushTokenString` as an overload to `Purchases.setPushToken`.
- Renamed `PurchasesDelegate.purchases(_:shouldPurchasePromoProduct:defermentBlock:)` to `PurchasesDelegate.purchases(_ purchases: Purchases, readyForPromotedProduct product: StoreProduct, purchase:)` to clarify its usage (see #1460).

#### Other:

- Added workaround for StoreKit 1 incorrectly reporting purchase cancellations #1450

- MagicWeatherSwiftUI now includes an example for using `purchases(:shouldPurchasePromoProduct:defermentBlock:)` #1459

- Various documentation improvements
- Many improvements to error reporting and logging to help debugging.
- Optimized StoreKit 2 purchasing by eliminating a duplicate API request.
- A lot of under-the-hood improvements, mainly focusing on networking. If you see any issues we'd appreciate [bug reports](https://github.com/RevenueCat/purchases-ios/issues/new?assignees=&labels=bug&template=bug_report.md&title=)!

- Additional under-the-hood improvements, continuing to focus on network requests and tests.
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
## 4.3.0

#### API updates:

- Introduced new `Storefront` type to abstract SK1's `SKStorefront` and SK2's `StoreKit.Storefront`.
- Exposed `Storefront.currentStorefront`.
- Added new `ErrorCode.offlineConnectionError` to differenciate offline errors versus the more generic `.networkError`.
- Added `Purchases-setFirebaseAppInstanceID` to allow associating RevenueCat users with Firebase.
- Added `Purchases.setPushTokenString` as an overload to `Purchases.setPushToken`.
- Renamed `PurchasesDelegate.purchases(_:shouldPurchasePromoProduct:defermentBlock:)` to `PurchasesDelegate.purchases(_ purchases: Purchases, readyForPromotedProduct product: StoreProduct, purchase:)` to clarify its usage (see #1460).

#### Other:

- Many improvements to error reporting and logging to help debugging.
- Optimized StoreKit 2 purchasing by eliminating a duplicate API request.
- A lot of under-the-hood improvements, mainly focusing on networking. If you see any issues we'd appreciate [bug reports](https://github.com/RevenueCat/purchases-ios/issues/new?assignees=&labels=bug&template=bug_report.md&title=)!


## 4.2.1

- Fixed a potential race condition when syncing user attributes #1479
Expand Down
2 changes: 1 addition & 1 deletion RevenueCat.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = "RevenueCat"
s.version = "4.3.0-SNAPSHOT"
s.version = "4.4.0-SNAPSHOT"
s.summary = "Subscription and in-app-purchase backend service."

s.description = <<-DESC
Expand Down
2 changes: 1 addition & 1 deletion Sources/CodableExtensions/PeriodType+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extension PeriodType: Decodable {
}

guard let type = Self.mapping[periodTypeString] else {
throw CodableError.unexpectedValue(PeriodType.self)
throw CodableError.unexpectedValue(PeriodType.self, periodTypeString)
}

self = type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ extension PurchaseOwnershipType: Decodable {
if let type = Self.mapping[purchaseOwnershipTypeString] {
self = type
} else {
Logger.error(Strings.codable.unexpectedValueError(type: PurchaseOwnershipType.self))
Logger.error(Strings.codable.unexpectedValueError(type: PurchaseOwnershipType.self,
value: purchaseOwnershipTypeString))
self = .unknown
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/CodableExtensions/Store+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ extension Store: Decodable {
}

guard let type = Self.mapping[storeString] else {
throw CodableError.unexpectedValue(Store.self)
throw CodableError.unexpectedValue(Store.self, storeString)
}

self = type
Expand Down
25 changes: 14 additions & 11 deletions Sources/FoundationExtensions/JSONDecoder+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,25 @@

import Foundation

enum CodableError: Error, CustomStringConvertible {
enum CodableError: Error, CustomStringConvertible, LocalizedError {

case unexpectedValue(Any.Type)
case unexpectedValue(Any.Type, Any)
case valueNotFound(value: Any.Type, context: DecodingError.Context)
case invalidJSONObject(value: [String: Any])

var description: String {
switch self {
case let .unexpectedValue(type):
return Strings.codable.unexpectedValueError(type: type).description
case let .unexpectedValue(type, value):
return Strings.codable.unexpectedValueError(type: type, value: value).description
case let .valueNotFound(value, context):
return Strings.codable.valueNotFoundError(value: value, context: context).description
case let .invalidJSONObject(value):
return Strings.codable.invalid_json_error(jsonData: value).description
}
}

var errorDescription: String? { return self.description }

}

extension JSONDecoder {
Expand Down Expand Up @@ -104,7 +107,7 @@ extension JSONSerialization {
let object = try JSONSerialization.jsonObject(with: data)

guard let object = object as? [String: Any] else {
throw CodableError.unexpectedValue(type(of: object))
throw CodableError.unexpectedValue(type(of: object), object)
}

return object
Expand All @@ -122,14 +125,14 @@ private extension ErrorUtils {
}

switch decodingError {
case .dataCorrupted(let context):
case let .dataCorrupted(context):
Logger.error(Strings.codable.corrupted_data_error(context: context))
case .keyNotFound(let key, let context):
case let .keyNotFound(key, context):
// This is expected to happen occasionally, the backend doesn't always populate all key/values.
Logger.debug(Strings.codable.keyNotFoundError(key: key, context: context))
case .valueNotFound(let value, let context):
case let .valueNotFound(value, context):
Logger.debug(Strings.codable.valueNotFoundError(value: value, context: context))
case .typeMismatch(let type, let context):
case let .typeMismatch(type, context):
Logger.error(Strings.codable.typeMismatch(type: type, context: context))
@unknown default:
Logger.error("Unhandled DecodingError: \(decodingError)\n\(Strings.codable.decoding_error(decodingError))")
Expand All @@ -141,11 +144,11 @@ private extension ErrorUtils {
extension Encodable {

func asDictionary() throws -> [String: Any] {
let data = try JSONEncoder().encode(self)
let data = try JSONEncoder.default.encode(self)
let result = try JSONSerialization.jsonObject(with: data, options: [])

guard let result = result as? [String: Any] else {
throw CodableError.unexpectedValue(type(of: result))
throw CodableError.unexpectedValue(type(of: result), result)
}

return result
Expand Down
2 changes: 1 addition & 1 deletion Sources/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<key>CFBundlePackageType</key>
<string>$(PRODUCT_BUNDLE_PACKAGE_TYPE)</string>
<key>CFBundleShortVersionString</key>
<string>4.3.0</string>
<string>4.4.0</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>LSApplicationCategoryType</key>
Expand Down
20 changes: 10 additions & 10 deletions Sources/Logging/Strings/CodableStrings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import Foundation
// swiftlint:disable identifier_name
enum CodableStrings {

case unexpectedValueError(type: Any.Type)
case unexpectedValueError(type: Any.Type, value: Any)
case valueNotFoundError(value: Any.Type, context: DecodingError.Context)
case keyNotFoundError(key: CodingKey, context: DecodingError.Context)
case invalid_json_error(jsonData: [String: Any])
Expand All @@ -30,21 +30,21 @@ extension CodableStrings: CustomStringConvertible {

var description: String {
switch self {
case .unexpectedValueError(let type):
return "Found unexpected value for type: \(type)"
case .valueNotFoundError(let value, let context):
case let .unexpectedValueError(type, value):
return "Found unexpected value '\(value)' for type '\(type)'"
case let .valueNotFoundError(value, context):
let description = context.debugDescription
return "No value found for: \(value), codingPath: \(context.codingPath), description:\n\(description)"
case .keyNotFoundError(let key, let context):
case let .keyNotFoundError(key, context):
let description = context.debugDescription
return "Key '\(key)' not found, codingPath: \(context.codingPath), description:\n\(description)"
case .invalid_json_error(let jsonData):
case let .invalid_json_error(jsonData):
return "The given json data was not valid: \n\(jsonData)"
case .decoding_error(let error):
return "Couldn't decode data from json. Error:\n\(error.localizedDescription))"
case .corrupted_data_error(let context):
case let .decoding_error(error):
return "Couldn't decode data from json. Error:\n\(error.localizedDescription)"
case let .corrupted_data_error(context):
return "Couldn't decode data from json, it was corrupted: \(context)"
case .typeMismatch(let type, let context):
case let .typeMismatch(type, context):
let description = context.debugDescription
return "Type '\(type)' mismatch, codingPath:\(context.codingPath), description:\n\(description)"
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Misc/SystemInfo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class SystemInfo {
}

static var frameworkVersion: String {
return "4.3.0-SNAPSHOT"
return "4.4.0-SNAPSHOT"
}

static var systemVersion: String {
Expand Down
36 changes: 23 additions & 13 deletions Sources/Purchasing/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,23 @@ import Foundation
weekly
}

extension PackageType: CaseIterable {}

extension PackageType: CustomDebugStringConvertible {

/// A textual description of the type suitable for debugging.
public var debugDescription: String {
let className = String(describing: PackageType.self)

switch self {
case .unknown: return "\(className).unknown"
case .custom: return "\(className).custom"
default: return "\(className).\(self.description ?? "")"
}
}

}

private extension PackageType {

var description: String? {
Expand All @@ -57,20 +74,13 @@ private extension PackageType {
case .monthly: return "$rc_monthly"
case .weekly: return "$rc_weekly"
}

}

static var typesByDescription: [String: PackageType] {
[
"$rc_lifetime": .lifetime,
"$rc_annual": .annual,
"$rc_six_month": .sixMonth,
"$rc_three_month": .threeMonth,
"$rc_two_month": .twoMonth,
"$rc_monthly": .monthly,
"$rc_weekly": .weekly
]
}
static let typesByDescription: [String: PackageType] = PackageType
.allCases
.filter { $0.description != nil }
.dictionaryWithKeys { $0.description! }

}

///
Expand Down Expand Up @@ -148,7 +158,7 @@ private extension PackageType {
* - Parameter string: A string that maps to a enumeration value of type ``PackageType``
* - Returns: a ``PackageType`` for the given string.
*/
class func packageType(from string: String) -> PackageType {
static func packageType(from string: String) -> PackageType {
if let packageType = PackageType.typesByDescription[string] {
return packageType
}
Expand Down
Loading

0 comments on commit 5268820

Please sign in to comment.