Skip to content

Commit

Permalink
PurchaseController mainactor conformance moved to funcs and setUserAt…
Browse files Browse the repository at this point in the history
…tributesDictionary changed for objc
  • Loading branch information
yusuftor committed Mar 9, 2023
1 parent 9f93421 commit e9a6661
Show file tree
Hide file tree
Showing 9 changed files with 20 additions and 14 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@ The changelog for `SuperwallKit`. Also see the [releases](https://github.com/sup

- Changes Objective-C method `getTrackInfo` to `getTrackResult` to be in line with the Swift API.
- Removes the error case from the `TrackResult` and adds in `userIsSubscribed` and `paywallNotAvailable` cases.
- Moves main actor conformance to functions of PurchaseController protocol rather than the whole protocol.
- Changes Objective-C method `setUserAttributesDictionary(_:)` to `setUserAttributes(_:)`.

### Fixes

- Makes `NetworkEnvironment` Objective-C compatible.
- Fixes an issue where a manually dismissed modally presented paywall wouldn't properly dismiss.
- Fixes race condition when calling identify and tracking a paywall.

## 3.0.0-beta.6

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ - (nullable NSString *)name {

- (void)setName:(nullable NSString *)name {
id userAttributeFirstName = name ? : [NSNull null];
[[Superwall sharedInstance] setUserAttributesDictionary:@{ kUserAttributesFirstNameKey : userAttributeFirstName }];
[[Superwall sharedInstance] setUserAttributes:@{ kUserAttributesFirstNameKey : userAttributeFirstName }];
}

#pragma mark - Public Methods
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import StoreKit
///
/// To learn how to implement the ``PurchaseController`` in your app
/// and best practices, see <doc:AdvancedConfiguration>.
@MainActor
public protocol PurchaseController: AnyObject {
/// Called when the user initiates purchasing of a product.
///
Expand All @@ -31,6 +30,7 @@ public protocol PurchaseController: AnyObject {
///
/// - Returns: A``PurchaseResult`` object, which is the result of your purchase logic.
/// **Note**: Make sure you handle all cases of ``PurchaseResult``.
@MainActor
func purchase(product: SKProduct) async -> PurchaseResult

/// Called when the user initiates a restore.
Expand All @@ -39,5 +39,6 @@ public protocol PurchaseController: AnyObject {
/// and return its result.
///
/// - Returns: A boolean that's `true` if the user's purchases were restored or `false` if they weren't.
@MainActor
func restorePurchases() async -> Bool
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import StoreKit
///
/// To learn how to implement the ``PurchaseControllerObjc`` in your app
/// and best practices, see <doc:AdvancedConfiguration>.
@MainActor
@objc(SWKPurchaseController)
public protocol PurchaseControllerObjc: AnyObject {
/// Called when the user initiates purchasing of a product.
Expand All @@ -33,6 +32,7 @@ public protocol PurchaseControllerObjc: AnyObject {
/// Call this with the result of your purchase logic. When you pass a `.failed` result, make sure you also pass
/// the error.
/// **Note:** Make sure you handle all cases of ``PurchaseResult``.
@MainActor
@objc func purchase(
product: SKProduct,
completion: @escaping (PurchaseResultObjc, Error?) -> Void
Expand All @@ -45,5 +45,6 @@ public protocol PurchaseControllerObjc: AnyObject {
///
/// - Parameters:
/// - completion: Call the completion with `true` if the user's purchases were restored or `false` if they weren't.
@MainActor
@objc func restorePurchases(completion: @escaping (Bool) -> Void)
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ The ``Superwall`` class is used to access all the features of the SDK. Before us
- ``getTrackResult(forEvent:params:)-1qexk``
- ``getTrackResult(forEvent:params:completion:)``
- ``getTrackResult(forEvent:params:)-2j7qn``
- ``getTrackResult(forEvent:)``
- ``dismiss()-844a9``
- ``dismiss()-4objm``
- ``dismiss(completion:)``
Expand All @@ -64,8 +65,8 @@ The ``Superwall`` class is used to access all the features of the SDK. Before us
- ``identify(userId:)``
- ``IdentityOptions``
- ``reset()``
- ``setUserAttributes(_:)``
- ``setUserAttributesDictionary(_:)``
- ``setUserAttributes(_:)-1wql2``
- ``setUserAttributes(_:)-8jken``
- ``removeUserAttributes(_:)``
- ``userAttributes``

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Set user attributes for use in your paywalls and the dashboard.

You can display information about the user on the paywall by setting user attributes.

You do this by passing a `[String: Any?]` dictionary of attributes to ``Superwall/setUserAttributes(_:)``:
You do this by passing a `[String: Any?]` dictionary of attributes to ``Superwall/setUserAttributes(_:)-1wql2``:

```swift
extension SuperwallService {
Expand Down
4 changes: 2 additions & 2 deletions Sources/SuperwallKit/Identity/UserAttributes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ extension Superwall {
///
/// ```
/// NSDictionary *userAttributes = @{ key : value, key2 : value2};
/// [[Superwall sharedInstance] setUserAttributesDictionary: userAttributes];
/// [[Superwall sharedInstance] setUserAttributes:userAttributes];
/// ```
///
/// - Parameters:
Expand All @@ -56,7 +56,7 @@ extension Superwall {
/// Note: Keys beginning with `$` are reserved for Superwall and will be dropped. Arrays and dictionaries
/// as values are not supported at this time, and will be dropped.
@available(swift, obsoleted: 1.0)
@objc public func setUserAttributesDictionary(_ attributes: NSDictionary) {
@objc public func setUserAttributes(_ attributes: NSDictionary) {
var swiftDictionary: [String: Any?] = [:]
let keys = attributes.allKeys.compactMap { $0 as? String }
for key in keys {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ extension Superwall {
// MARK: - Objective-C-only Track
/// An Objective-C-only method that shows a paywall to the user when: An event you provide is tied to an
/// active trigger inside a campaign on the [Superwall Dashboard](https://superwall.com/dashboard);
/// and the user matches a rule in the campaign. **Note**: Please use ``Superwall/setUserAttributes(_:)``
/// and the user matches a rule in the campaign. **Note**: Please use ``Superwall/setUserAttributes(_:)-1wql2``
/// if you’re using Swift.
///
/// Triggers enable you to retroactively decide where or when to show a specific paywall in your app. Use this method
Expand Down Expand Up @@ -215,7 +215,7 @@ extension Superwall {

/// An Objective-C-only method that shows a paywall to the user when: An event you provide is tied to an
/// active trigger inside a campaign on the [Superwall Dashboard](https://superwall.com/dashboard);
/// and the user matches a rule in the campaign. **Note**: Please use ``Superwall/setUserAttributes(_:)``
/// and the user matches a rule in the campaign. **Note**: Please use ``Superwall/setUserAttributes(_:)-1wql2``
/// if you’re using Swift.
///
/// Triggers enable you to retroactively decide where or when to show a specific paywall in your app. Use this method
Expand All @@ -239,7 +239,7 @@ extension Superwall {

/// An Objective-C-only method that shows a paywall to the user when: An event you provide is tied to an
/// active trigger inside a campaign on the [Superwall Dashboard](https://superwall.com/dashboard);
/// and the user matches a rule in the campaign. **Note**: Please use ``Superwall/setUserAttributes(_:)``
/// and the user matches a rule in the campaign. **Note**: Please use ``Superwall/setUserAttributes(_:)-1wql2``
/// if you’re using Swift.
///
/// Triggers enable you to retroactively decide where or when to show a specific paywall in your app. Use this method
Expand Down Expand Up @@ -269,7 +269,7 @@ extension Superwall {

/// An Objective-C-only method that shows a paywall to the user when: An event you provide is tied to an
/// active trigger inside a campaign on the [Superwall Dashboard](https://superwall.com/dashboard);
/// and the user matches a rule in the campaign. **Note**: Please use ``Superwall/setUserAttributes(_:)``
/// and the user matches a rule in the campaign. **Note**: Please use ``Superwall/setUserAttributes(_:)-1wql2``
/// if you’re using Swift.
///
/// Triggers enable you to retroactively decide where or when to show a specific paywall in your app. Use this method
Expand Down Expand Up @@ -310,7 +310,7 @@ extension Superwall {

/// An Objective-C-only method that shows a paywall to the user when: An event you provide is tied to an
/// active trigger inside a campaign on the [Superwall Dashboard](https://superwall.com/dashboard);
/// and the user matches a rule in the campaign. **Note**: Please use ``Superwall/setUserAttributes(_:)``
/// and the user matches a rule in the campaign. **Note**: Please use ``Superwall/setUserAttributes(_:)-1wql2``
/// if you’re using Swift.
///
/// Triggers enable you to retroactively decide where or when to show a specific paywall in your app. Use this method
Expand Down
2 changes: 1 addition & 1 deletion Sources/SuperwallKit/Superwall.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public final class Superwall: NSObject, ObservableObject {
}
}

/// Properties stored about the user, set using ``setUserAttributes(_:)``.
/// Properties stored about the user, set using ``setUserAttributes(_:)-1wql2``.
public var userAttributes: [String: Any] {
return dependencyContainer.identityManager.userAttributes
}
Expand Down

0 comments on commit e9a6661

Please sign in to comment.