Skip to content

Commit

Permalink
add 'removeTransactionsForProductIdentifier' to RMStoreUserDefaultsPe…
Browse files Browse the repository at this point in the history
…rsistence robotmedia#175
  • Loading branch information
everappz committed Mar 24, 2024
1 parent f2206e4 commit ed1d14a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions RMStore/Optional/RMStoreUserDefaultsPersistence.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
*/
- (void)removeTransactions;

/** Remove transactions from user defaults via specific ProductIdentifier.
*/
- (void)removeTransactionsForProductIdentifier:(NSString *)productIdentifier;

/** Consume the given product if available. Intended for consumable products.
@param productIdentifier Identifier of the product to be consumed.
@return YES if the product was consumed, NO otherwise.
Expand Down
9 changes: 9 additions & 0 deletions RMStore/Optional/RMStoreUserDefaultsPersistence.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,15 @@ - (void)removeTransactions
[defaults synchronize];
}

- (void)removeTransactionsForProductIdentifier:(NSString *)productIdentifier{
NSUserDefaults *defaults = [self userDefaults];
NSDictionary *purchases = [defaults objectForKey:RMStoreTransactionsUserDefaultsKey] ? : @{};
NSMutableDictionary *updatedPurchases = [NSMutableDictionary dictionaryWithDictionary:purchases];
[updatedPurchases removeObjectForKey:productIdentifier];
[defaults setObject:updatedPurchases forKey:RMStoreTransactionsUserDefaultsKey];
[defaults synchronize];
}

- (BOOL)consumeProductOfIdentifier:(NSString*)productIdentifier
{
NSUserDefaults *defaults = [self userDefaults];
Expand Down

0 comments on commit ed1d14a

Please sign in to comment.