Skip to content

Commit

Permalink
removes call to close in onDetachedToEngine and creates new close fun… (
Browse files Browse the repository at this point in the history
  • Loading branch information
vegaro committed Oct 28, 2021
1 parent 255ef75 commit e737eaf
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,6 @@ private void onAttachedToEngine(BinaryMessenger messenger, Context applicationCo

@Override
public void onDetachedFromEngine(@NonNull FlutterPluginBinding binding) {
try {
Purchases.getSharedInstance().close();
} catch (UninitializedPropertyAccessException e) {
// there's no instance so all good
}
if (channel != null) {
channel.setMethodCallHandler(null);
}
Expand Down Expand Up @@ -299,6 +294,9 @@ public void onMethodCall(@NonNull MethodCall call, @NonNull Result result) {
List<Integer> features = call.argument("features");
canMakePayments(features, result);
break;
case "close":
close(result);
break;
default:
result.notImplemented();
break;
Expand Down Expand Up @@ -576,6 +574,15 @@ public void onError(@Nullable ErrorContainer errorContainer) {
});
}

private void close(final Result result) {
try {
Purchases.getSharedInstance().close();
} catch (UninitializedPropertyAccessException e) {
// there's no instance so all good
}
result.success(null);
}

@NotNull
private OnResult getOnResult(final Result result) {
return new OnResult() {
Expand Down
6 changes: 6 additions & 0 deletions ios/Classes/PurchasesFlutterPlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@ - (void)handleMethodCall:(FlutterMethodCall *)call
[self paymentDiscountForProductIdentifier:productIdentifier
discountIdentifier:discountIdentifier
result:result];
} else if ([@"close" isEqualToString:call.method]) {
[self closeWithResult:result];
} else {
result(FlutterMethodNotImplemented);
}
Expand Down Expand Up @@ -455,6 +457,10 @@ - (void)paymentDiscountForProductIdentifier:(NSString *)productIdentifier
}];
}

- (void)closeWithResult:(FlutterResult)result {
result(nil);
}

#pragma mark -
#pragma mark Delegate Methods

Expand Down
6 changes: 6 additions & 0 deletions lib/purchases_flutter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,12 @@ class Purchases {
});
return PaymentDiscount.fromJson(result);
}

/// Android only. Call close when you are done with this instance of Purchases to disconnect
/// from the billing services and clean up resources
static Future<void> close() async {
await _channel.invokeMethod('close');
}
}

/// This class holds the information used when upgrading from another sku.
Expand Down

0 comments on commit e737eaf

Please sign in to comment.