diff --git a/RMStore/Optional/RMStoreUserDefaultsPersistence.h b/RMStore/Optional/RMStoreUserDefaultsPersistence.h index 01cf626..9d27cb9 100644 --- a/RMStore/Optional/RMStoreUserDefaultsPersistence.h +++ b/RMStore/Optional/RMStoreUserDefaultsPersistence.h @@ -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. diff --git a/RMStore/Optional/RMStoreUserDefaultsPersistence.m b/RMStore/Optional/RMStoreUserDefaultsPersistence.m index 9faca37..833257b 100644 --- a/RMStore/Optional/RMStoreUserDefaultsPersistence.m +++ b/RMStore/Optional/RMStoreUserDefaultsPersistence.m @@ -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];