Skip to content

[in_app_purchase] initialization problem on iOS #43957

@ilyasKerbal

Description

@ilyasKerbal

Target Platform: IOS only. (Works on Android)

Issue: The app doesn't initialize the purchases until you click the button to buy again. In other words, the plugin doesn't verify previous purchases when opened.

Future<void> initializeIap() async {
    iapAvailable = await _iap.isAvailable();
    if (iapAvailable) {
      await _getProducts();
      await _getPastPurchases();
      _subscription = _iap.purchaseUpdatedStream.listen((data) {
        _purchases.addAll(data);
        _verifyPurchase();
      });
      _verifyPurchase();
    }
  }
Future<void> _getPastPurchases() async {
    QueryPurchaseDetailsResponse response = await _iap.queryPastPurchases();
    //TODO: IOS Complete Purchases
    for (PurchaseDetails purchase in response.pastPurchases) {
      if (Platform.isIOS) {
        InAppPurchaseConnection.instance.completePurchase(purchase);
      }
    }
    _purchases = response.pastPurchases;
  }
Future<void> _getProducts() async {
    Set<String> ids = Set.from([offerId]);
    ProductDetailsResponse response = await _iap.queryProductDetails(ids);
    _products = response.productDetails;
    notifyListeners();
  }

Version 0.2.1

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listcustomer: crowdAffects or could affect many people, though not necessarily a specific customer.p: in_app_purchasePlugin for in-app purchasepackageflutter/packages repository. See also p: labels.platform-iosiOS applications specificallyr: timeoutIssue is closed due to author not providing the requested details in time

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions