You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flutter开发:iOS订阅促销优惠使用问题求助

解决Flutter iOS订阅促销优惠的两个问题

问题1:区分多个折扣优惠

SKProductDiscountWrapper确实没有直接的自定义标识符,但可以通过它自带的属性组合定位特定优惠:

  • 折扣类型(paymentMode):比如SKProductDiscountPaymentMode.freeTrial对应免费试用,SKProductDiscountPaymentMode.fixedPrice对应固定价格折扣,SKProductDiscountPaymentMode.payAsYouGo对应按周期折扣
  • 周期数(numberOfPeriods):比如首月折扣对应1个周期,季度折扣对应3个周期
  • 折扣价格(price):结合货币代码(priceLocale)判断折扣力度

举个筛选免费试用优惠的代码示例:

if (Platform.isIOS) {
  final appStoreProduct = productDetails as AppStoreProductDetails;
  final freeTrialDiscount = appStoreProduct.skProduct.discounts.firstWhere(
    (discount) => discount.paymentMode == SKProductDiscountPaymentMode.freeTrial,
    orElse: () => null,
  );
}

如果需要更精准区分,建议在App Store Connect配置优惠时,给同类型优惠设置统一的周期、价格规则,这样代码里就能通过属性组合筛选到目标折扣。

问题2:购买时应用折扣

首先注意:订阅类商品要使用buySubscriptions方法,而非buyNonConsumable(后者针对非消耗品)。其次,AppStorePurchaseParam支持传入折扣参数,只需将选中的SKProductDiscountWrapper赋值给discount字段即可:

if (Platform.isIOS && targetDiscount != null) {
  final purchaseParam = AppStorePurchaseParam(
    productDetails: productDetails,
    discount: targetDiscount, // 传入目标折扣对象
  );
  await _inAppPurchase.buySubscriptions(purchaseParam: purchaseParam);
}

这样Apple Pay会自动应用指定折扣完成结算。

内容的提问来源于stack exchange,提问作者Alaa Eddine Cherbib

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.20 09:54:33