Skip to content

Commit

Permalink
User defaults Suite Name option in setup (RevenueCat#70)
Browse files Browse the repository at this point in the history
* added userDefaultsSuiteName, ignored in android

* added description for the userDefaultsSuiteName property
  • Loading branch information
aboedo authored Jun 25, 2020
1 parent ac4096a commit 858bbc1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ public void onMethodCall(MethodCall call, Result result) {
String apiKey = call.argument("apiKey");
String appUserId = call.argument("appUserId");
Boolean observerMode = call.argument("observerMode");
String userDefaultsSuiteName = call.argument("userDefaultsSuiteName"); // iOS-only, unused.
setupPurchases(apiKey, appUserId, observerMode, result);
break;
case "setFinishTransactions":
Expand Down
12 changes: 10 additions & 2 deletions ios/Classes/PurchasesFlutterPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
NSString *apiKey = arguments[@"apiKey"];
NSString *appUserID = arguments[@"appUserId"];
BOOL observerMode = [arguments[@"observerMode"] boolValue];
[self setupPurchases:apiKey appUserID:appUserID observerMode:observerMode result:result];
NSString * _Nullable userDefaultsSuiteName = arguments[@"userDefaultsSuiteName"];
[self setupPurchases:apiKey appUserID:appUserID observerMode:observerMode userDefaultsSuiteName:userDefaultsSuiteName result:result];
} else if ([@"setAllowSharingStoreAccount" isEqualToString:call.method]) {
[self setAllowSharingStoreAccount:[arguments[@"allowSharing"] boolValue] result:result];
} else if ([@"setFinishTransactions" isEqualToString:call.method]) {
Expand Down Expand Up @@ -108,12 +109,19 @@ - (void)handleMethodCall:(FlutterMethodCall *)call result:(FlutterResult)result
- (void)setupPurchases:(NSString *)apiKey
appUserID:(NSString *)appUserID
observerMode:(BOOL)observerMode
userDefaultsSuiteName:(nullable NSString *)userDefaultsSuiteName
result:(FlutterResult)result
{
if ([appUserID isKindOfClass:NSNull.class]) {
appUserID = nil;
}
if ([userDefaultsSuiteName isKindOfClass:NSNull.class]) {
userDefaultsSuiteName = nil;
}
[RCPurchases configureWithAPIKey:apiKey
appUserID:appUserID
observerMode:observerMode
userDefaults:nil
userDefaultsSuiteName:userDefaultsSuiteName
platformFlavor:self.platformFlavor
platformFlavorVersion:self.platformFlavorVersion];
RCPurchases.sharedPurchases.delegate = self;
Expand Down
22 changes: 12 additions & 10 deletions lib/purchases_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,19 @@ class Purchases {
/// [observerMode] An optional boolean. Set this to TRUE if you have your own
/// IAP implementation and want to use only RevenueCat's backend.
/// Default is FALSE.
///
/// [userDefaultsSuiteName] iOS-only, will be ignored for Android.
/// Set this if you would like the RevenueCat SDK to store its preferences in a different
/// NSUserDefaults suite, otherwise it will use standardUserDefaults.
/// Default is null, which will make the SDK use standardUserDefaults.
static Future<void> setup(String apiKey,
{String appUserId, bool observerMode = false}) async {
if (appUserId == null) {
return await _channel.invokeMethod('setupPurchases', {'apiKey': apiKey});
} else {
return await _channel.invokeMethod('setupPurchases', {
'apiKey': apiKey,
'appUserId': appUserId,
'observerMode': observerMode
});
}
{String appUserId, bool observerMode = false, String userDefaultsSuiteName}) async {
return await _channel.invokeMethod('setupPurchases', {
'apiKey': apiKey,
'appUserId': appUserId,
'observerMode': observerMode,
'userDefaultsSuiteName': userDefaultsSuiteName
});
}

// Default to TRUE, set this to FALSE if you are consuming and acknowledging transactions outside of the Purchases SDK.
Expand Down

0 comments on commit 858bbc1

Please sign in to comment.