Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: sharedPurchases nullability #508

Merged
merged 3 commits into from
May 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions Purchases/Public/RCPurchases.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,18 @@ NS_SWIFT_NAME(Purchases)

/**
@return A singleton `RCPurchases` object. Call this after a configure method to access the singleton.
@note: If the SDK has not been configured, calls to sharedPurchases will raise an exception. Make sure to configure the SDK before making calls to sharedPurchases.
*/
@property (class, nonatomic, readonly) RCPurchases *sharedPurchases;

#pragma mark Configuration

/**
@note True if the SDK has been configured, false otherwise. This property should only be used in special circumstances. If the shared instance has not been configured,
calls made to it will raise an exception.
*/
@property (class, nonatomic, readonly) BOOL isConfigured;
Copy link
Member Author

Choose a reason for hiding this comment

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

This doesn't exist in Android, and I'm not 100% sure it's needed.

However, we are changing the behavior of the SDK, so maybe it's helpful for some folks if they're migrating behaviors.

Note that the previous behavior is the no-op, which no one should really have been relying on.

Copy link
Contributor

Choose a reason for hiding this comment

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

sounds good


/** Set this to true if you are passing in an appUserID but it is anonymous, this is true by default if you didn't pass an appUserID
If a user tries to purchase a product that is active on the current app store account, we will treat it as a restore and alias
the new ID with the previous id.
Expand Down
8 changes: 5 additions & 3 deletions Purchases/Public/RCPurchases.m
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,12 @@ - (void)setFinishTransactions:(BOOL)finishTransactions {
self.systemInfo.finishTransactions = finishTransactions;
}

+ (BOOL)isConfigured {
return _sharedPurchases != nil;
}

+ (instancetype)sharedPurchases {
if (!_sharedPurchases) {
RCWarnLog(@"%@", RCStrings.configure.no_singleton_instance);
}
NSCAssert(_sharedPurchases, RCStrings.configure.no_singleton_instance);
return _sharedPurchases;
}

Expand Down
12 changes: 12 additions & 0 deletions PurchasesTests/Purchasing/PurchasesTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,19 @@ class PurchasesTests: XCTestCase {
setupPurchases()
expect(self.purchases).toNot(beNil())
}

func testUsingSharedInstanceWithoutInitializingRaisesException() {
expect{ Purchases.shared }.to(raiseException())
setupPurchases()
expect{ Purchases.shared }.toNot(raiseException())
}

func testIsConfiguredReturnsCorrectvalue() {
expect(Purchases.isConfigured) == false
setupPurchases()
expect(Purchases.isConfigured) == true
}

func testFirstInitializationCallDelegate() {
setupPurchases()
expect(self.purchasesDelegate.purchaserInfoReceivedCount).toEventually(equal(1))
Expand Down