使用RevenueCat无法完成订阅购买,遇App Store认证失败错误求助
问题:Flutter + RevenueCat 订阅购买失败,提示App Store问题
能正常获取订阅产品,但无法完成交易流程,以下是相关错误信息、代码及已完成配置,请求协助排查。
错误信息
应用内捕获的错误
PlatformException(2, There was a problem with the App Store., {userCancelled: false, message: There was a problem with the App Store., underlyingErrorMessage: An unknown error occurred, readableErrorCode: STORE_PROBLEM, code: 2, readable_error_code: STORE_PROBLEM}, null)
真机测试日志
<SKPaymentQueue: 0x2835da000>: Payment completed with error: Error Domain=ASDErrorDomain Code=500 "Unhandled exception" UserInfo={NSUnderlyingError=0x28398b6f0 {Error Domain=AMSErrorDomain Code=100 "Authentication Failed" UserInfo={NSMultipleUnderlyingErrorsKey=( "Error Domain=AMSErrorDomain Code=2 \"An unknown error occurred. Please try again.\" UserInfo={NSLocalizedDescription=An unknown error occurred. Please try again.}", "Error Domain=AMSServerErrorDomain Code=-5000 \"(null)\" UserInfo={failureType=-5000, m-allowed=false, pings=(\n), cancel-purchase-batch=true, customerMessage=The Apple ID you entered couldn’t be found or your password was incorrect. Please try again.}" ), NSLocalizedDescription=Authentication Failed, NSLocalizedFailureReason=The authentication failed.}}, storefront-country-code=USA, client-environment-type=Sandbox, AMSServerErrorCode=0, NSLocalizedFailureReason=An unknown error occurred, NSLocalizedDescription=Unhandled exception} [purchases] DEBUG: ℹ️ StoreKit1Wrapper (0x00000002813c3ea0) updatedTransaction: all_features_10_1m (An unknown error occurred) 2 [error] ERROR: 🍎‼️ There was a problem with the App Store. [purchases] INFO: 💰 Finishing transaction '770D6039-33FC-45E4-955B-B60C3892E409' for product 'all_features_10_1m' [purchases] ERROR: 💰 Product purchase for 'all_features_10_1m' failed with error: Error Domain=RevenueCat.ErrorCode Code=2 "There was a problem with the App Store." UserInfo={source_file=RevenueCat/SKError+Extensions.swift:64, readable_error_code=STORE_PROBLEM, source_function=asPurchasesError, NSLocalizedDescription=There was a problem with the App Store., NSUnderlyingError=0x28398a760 {Error Domain=SKErrorDomain Code=0 "An unknown error occurred" UserInfo={NSLocalizedDescription=An unknown error occurred, NSUnderlyingError=0x2839892c0 {Error Domain=ASDErrorDomain Code=500 "Unhandled exception" UserInfo={NSUnderlyingError=0x28398b6f0 {Error Domain=AMSErrorDomain Code=100 "Authentication Failed" UserInfo=0x28229d1c0 (not displayed)}, NSLocalizedDescription=Unhandled exception, NSLocalizedFailureReason=An unknown error occurred}}}}} [purchases] DEBUG: ℹ️ StoreKit1Wrapper (0x00000002813c3ea0) removedTransaction: all_features_10_1m (An unknown error occurred) ["NSLocalizedDescription": An unknown error occurred, "NSUnderlyingError": Error Domain=ASDErrorDomain Code=500 "Unhandled exception" UserInfo={NSUnderlyingError=0x28398b6f0 {Error Domain=AMSErrorDomain Code=100 "Authentication Failed" UserInfo={NSMultipleUnderlyingErrorsKey=( "Error Domain=AMSErrorDomain Code=2 \"An unknown error occurred. Please try again.\" UserInfo={NSLocalizedDescription=An unknown error occurred. Please try again.}", "Error Domain=AMSServerErrorDomain Code=-5000 \"(null)\" UserInfo={failureType=-5000, m-allowed=false, pings=(\n), cancel-purchase-batch=true, customerMessage=The Apple ID you entered couldn’t be found or your password was incorrect. Please try again.}" ), NSLocalizedDescription=Authentication Failed, NSLocalizedFailureReason=The authentication failed.}}, NSLocalizedDescription=Unhandled exception, NSLocalizedFailureReason=An unknown error occurred}] 2 flutter: error: PlatformException(2, There was a problem with the App Store., {userCancelled: false, message: There was a problem with the App Store., code: 2, underlyingErrorMessage: An unknown error occurred, readableErrorCode: STORE_PROBLEM, readable_error_code: STORE_PROBLEM}, null)
已完成的配置
- RevenueCat后台已配置对应产品
- Apple开发者后台创建了订阅产品,且开启应用内购买权限
相关代码
主入口代码
Future<void> main() async { await dotenv.load(); WidgetsFlutterBinding.ensureInitialized(); RevenueCat.init(); await Firebase.initializeApp( name: "thraive-5f2ab", options: DefaultFirebaseOptions.currentPlatform, ); runApp(MyApp()); }
RevenueCat工具类
import 'package:flutter_dotenv/flutter_dotenv.dart'; import 'package:purchases_flutter/models/offerings_wrapper.dart'; import 'package:purchases_flutter/purchases_flutter.dart'; class RevenueCat { static Future init() async { final revenueCat = PurchasesConfiguration(dotenv.env['REVENUE_CAT_APPLE_API_KEY']!); await Purchases.configure(revenueCat); } static Future<List<Offering>> fetchOfferss() async { print('fetchOffers()'); try { final offerings = await Purchases.getOfferings(); final current = offerings.current; return current == null ? [] : [current]; } catch (e) { return []; } } static Future<bool> purchasePackage(Package package) async { print('purchasePackage()'); try { await Purchases.purchasePackage(package); return true; } catch (e) { print('error: ${e}'); return false; } } }
订阅购买按钮处理代码
buyFirstSubscription() async { print('[fetchOffers]'); final offerings = await RevenueCat.fetchOfferss(); if (offerings.isEmpty) { Utils.showSnackBar('No subscriptions!'); } else { final offer = offerings.first; final packages = offerings .map((offer) => offer.availablePackages) .expand((pair) => pair) .toList(); // print(packages); bool purchaseResult = await RevenueCat.purchasePackage(packages[0]); } }
排查与解决步骤
验证沙盒测试账号
从日志中的customerMessage可以看出,沙盒账号验证失败。必须使用Apple官方沙盒测试账号(不是个人Apple ID),确保账号有效、密码正确,且退出设备上的个人Apple ID后再用沙盒账号登录。统一地区设置
日志显示storefront-country-code=USA,需确保沙盒账号所属地区为美国,同时设备的App Store地区也设置为美国,避免地区不匹配导致验证失败。修正RevenueCat初始化时机
主代码中RevenueCat.init()未加await,可能导致初始化未完成就执行后续操作,修改如下:Future<void> main() async { await dotenv.load(); WidgetsFlutterBinding.ensureInitialized(); await RevenueCat.init(); // 加上await确保初始化完成 await Firebase.initializeApp( name: "thraive-5f2ab", options: DefaultFirebaseOptions.currentPlatform, ); runApp(MyApp()); }优化购买错误处理
原购买方法仅返回bool,无法区分错误类型,建议修改为捕获具体错误并验证订阅状态:static Future<bool> purchasePackage(Package package) async { print('purchasePackage()'); try { final customerInfo = await Purchases.purchasePackage(package); // 检查是否有激活的订阅权限 return customerInfo.entitlements.active.isNotEmpty; } catch (e) { if (e is PlatformException) { print('Purchase error code: ${e.code}, message: ${e.message}'); // 区分用户取消、支付失败等不同错误 if (e.code == "USER_CANCELLED") { print("User cancelled purchase"); } } print('error: ${e}'); return false; } }检查应用签名与权限配置
- 确认Xcode中应用的Bundle ID与Apple开发者后台、RevenueCat后台完全一致
- 确保已开启In-App Purchase capability,且Provisioning Profile包含该权限
- 检查应用的签名是否有效,避免因签名问题导致无法连接App Store服务
确认网络环境
沙盒服务需要稳定的网络,避免使用VPN或代理导致连接异常,确保设备能正常访问Apple沙盒服务器。
内容的提问来源于stack exchange,提问作者user17281101
相关产品推荐
相关产品推荐

