14.8 C
New York
Monday, March 31, 2025

iOS App terminating whereas utilizing in_app_purchase into 18.3.1 into Flutter


I’m studying Flutter and carried out the in_app_purchase for for Android and iOS, nevertheless it really works superb into each platforms however having the under subject into iOS 18.3.1 . The model I’ve

in_app_purchase: ^3.1.13

I face this subject

flutter: Buy profitable!
flutter: Buy lastly :
*** Terminating app because of uncaught exception 'NSInvalidArgumentException', motive: '-[NSNull length]: unrecognized selector despatched to occasion 0x20c8db910'
*** First throw name stack:
(0x1a266a5fc 0x19fbe5244 0x1a27c3174 0x1a266d5c8 0x1a266cef0 0x1a125bbf0 0x1cfc08f64 0x1cfc066a8 0x1cfc05d18 0x1cfc052f4 0x1cfc07811 0x1cfc09a29 0x1cfbe2ddd 0x1cfbe2ddd 0x1cfbe2ddd 0x1cfbde2c5 0x1cfbde419 0x1cfbde2c5 0x1adf8fe39)
libc++abi: terminating because of uncaught exception of sort NSException

My supply code

Future purchasePlan(BasePlans basePlan, BuildContext context) async {
    attempt {
      isLoading.worth = true;
      print("purchasePlan referred to as : " + basePlan.id.toString());
      print("purchasePlan referred to as : " + basePlan.productDetails!.title);

      if (basePlan.productDetails == null) {
        error.worth = "Product not out there for buy.";
        print("Product not out there for buy");
        isLoading.worth = false;
        return;
      }
      purchasePending.worth = true;
      late PurchaseParam purchaseParam;

      if (Platform.isAndroid) {
        // Test for present subscriptions
        remaining GooglePlayPurchaseDetails? oldSubscription =
            _getOldSubscription(basePlan.productDetails!, purchases);
        purchaseParam = GooglePlayPurchaseParam(
          productDetails: basePlan.productDetails!,
          changeSubscriptionParam: (oldSubscription != null)
              ? ChangeSubscriptionParam(
                  oldPurchaseDetails: oldSubscription,
                  replacementMode: ReplacementMode.withoutProration)
              : null,
        );
      } else {

        print("basePlan.productDetails id: " + basePlan.productDetails!.id);
        print("basePlan.productDetails title : " +
            basePlan.productDetails!.title);
        print("basePlan.productDetails description : " +
            basePlan.productDetails!.description);
        print("basePlan.productDetails worth : " +
            basePlan.productDetails!.worth);
        print("basePlan.productDetails  rawPrice: " +
            basePlan.productDetails!.rawPrice.toString());
        print("basePlan.productDetails  currencyCode: " +
            basePlan.productDetails!.currencyCode.toString());
        print("basePlan.productDetails  currencySymbol: " +
            basePlan.productDetails!.currencySymbol.toString());

        purchaseParam = PurchaseParam(
          productDetails: basePlan.productDetails!,
        );

        print("basePlan.purchaseParam : " + purchaseParam.productDetails.id);
        print("basePlan.applicationUserName : " +
            purchaseParam.applicationUserName.toString());
      }

      attempt {
        await _inAppPurchasePlatform.buyNonConsumable(
            purchaseParam: purchaseParam);
        print("Buy profitable!");
      } catch (e, stacktrace) {
        print("Buy failed: $e");
        print("Stacktrace: $stacktrace");
        rethrow; // Protect the crash for additional debugging
      }
    } catch (e) {
      print("Buy error : $e");

      error.worth = "Buy error: $e";
      purchasePending.worth = false;
      isLoading.worth = false;

      String errorMessage = e.toString();
      String displayMessage="";

      // Test if the error accommodates the particular message
      if (errorMessage.accommodates('storekit_duplicate_product_object')) {
        displayMessage="There's a pending transaction for a similar product identifier. Please both look forward to it to be completed or end it manually utilizing `completePurchase` to keep away from edge instances.";
      } else {
        displayMessage="An sudden buy error occurred: $errorMessage";
      }

      Get.snackbar(
        "One thing went improper!",
        displayMessage,
        snackPosition: SnackPosition.BOTTOM,
      );
      return;
    } lastly {
      print("Buy lastly : ");
      isPurchasing.worth = false; // Set to false when buy is completed
      // isLoading.worth = false;
    }
  }

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest Articles