Flutter - IAP 错误代码 6 和消息 "the item you were attempting to purchase could not be found"
Flutter - IAP error code 6 with message "the item you were attempting to purchase could not be found"
我正在我的应用程序中进行应用内购买。我正在使用 Flutter-In-App-Purchase Plugin 来实现 IAP 功能。以下是我实现 IAP 的代码。
class InApp extends StatefulWidget {
@override
_InAppState createState() => _InAppState();
}
class _InAppState extends State<InApp> {
StreamSubscription _purchaseUpdatedSubscription;
StreamSubscription _purchaseErrorSubscription;
StreamSubscription _conectionSubscription;
final List<String> _productLists = Platform.isAndroid
? ["Buy Book"]
: ["Buy Book"];
List<IAPItem> _items = [];
List<PurchasedItem> _purchases = [];
@override
void initState() {
super.initState();
initPlatformState();
}
@override
void dispose() {
if (_conectionSubscription != null) {
_conectionSubscription.cancel();
_conectionSubscription = null;
}
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
// prepare
var result = await FlutterInappPurchase.instance.initConnection;
print('result: $result');
if (!mounted) return;
_conectionSubscription =
FlutterInappPurchase.connectionUpdated.listen((connected) {
print('connected: $connected');
});
_purchaseUpdatedSubscription =
FlutterInappPurchase.purchaseUpdated.listen((productItem) {
print('purchase-updated: $productItem');
});
_purchaseErrorSubscription =
FlutterInappPurchase.purchaseError.listen((purchaseError) {
print('purchase-error: $purchaseError');
});
}
void _requestPurchase(IAPItem item) {
FlutterInappPurchase.instance.requestPurchase(item.productId);
}
Future _getProduct() async {
List<IAPItem> items = await FlutterInappPurchase.instance.getProducts(_productLists);
for (var item in items) {
print('${item.toString()}');
this._items.add(item);
}
setState(() {
this._items = items;
this._purchases = [];
});
_getPurchases();
}
Future _getPurchases() async {
List<PurchasedItem> items = await FlutterInappPurchase.instance.getAvailablePurchases();
for (var item in items) {
print('${item.toString()}');
this._purchases.add(item);
}
setState(() {
this._items = [];
this._purchases = items;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: RaisedButton(
onPressed: () {
_requestPurchase(_items[0]);
},
child: Text("Buy Item"),
),
),
);
}
}
当我单击 BuyItem 并调用 requestPurchase() 方法时。我收到以下错误日志并收到类似 "the item you were attempting to purchase could not be found"
的错误
W/ActivityThread( 8794): handleWindowVisibility: no activity for token
android.os.BinderProxy@572f129 W/ProxyBillingActivity( 8794): Activity
finished with resultCode 0 and billing's responseCode: 6
W/BillingHelper( 8794): Couldn't find purchase lists, trying to find
single data. W/BillingHelper( 8794): Received a bad purchase data.
W/BillingHelper( 8794): Couldn't find single purchase data as well.
E/DoobooUtils( 8794): Error Code : 6 I/flutter ( 8794):
purchase-error: responseCode: 6, debugMessage: , code: E_UNKNOWN,
message: An unknown or unexpected error has occured. Please try again
later.
请提出解决方案。
谢谢。
我认为您的应用内商品将处于非活动状态。
默认情况下,当您在播放控制台中添加托管产品时,它会处于非活动状态。因此,只需在您的 google 游戏控制台帐户中访问您的应用内产品并验证它是否有效。
此外,请确保您 developing/testing 应用的 VersionCode 和 VersionName 至少应为 google 游戏开发者 console/play 商店中的版本。
对于 flutter,您可以在 pubspec.yaml 文件中检查版本控制。
我正在我的应用程序中进行应用内购买。我正在使用 Flutter-In-App-Purchase Plugin 来实现 IAP 功能。以下是我实现 IAP 的代码。
class InApp extends StatefulWidget {
@override
_InAppState createState() => _InAppState();
}
class _InAppState extends State<InApp> {
StreamSubscription _purchaseUpdatedSubscription;
StreamSubscription _purchaseErrorSubscription;
StreamSubscription _conectionSubscription;
final List<String> _productLists = Platform.isAndroid
? ["Buy Book"]
: ["Buy Book"];
List<IAPItem> _items = [];
List<PurchasedItem> _purchases = [];
@override
void initState() {
super.initState();
initPlatformState();
}
@override
void dispose() {
if (_conectionSubscription != null) {
_conectionSubscription.cancel();
_conectionSubscription = null;
}
}
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
// prepare
var result = await FlutterInappPurchase.instance.initConnection;
print('result: $result');
if (!mounted) return;
_conectionSubscription =
FlutterInappPurchase.connectionUpdated.listen((connected) {
print('connected: $connected');
});
_purchaseUpdatedSubscription =
FlutterInappPurchase.purchaseUpdated.listen((productItem) {
print('purchase-updated: $productItem');
});
_purchaseErrorSubscription =
FlutterInappPurchase.purchaseError.listen((purchaseError) {
print('purchase-error: $purchaseError');
});
}
void _requestPurchase(IAPItem item) {
FlutterInappPurchase.instance.requestPurchase(item.productId);
}
Future _getProduct() async {
List<IAPItem> items = await FlutterInappPurchase.instance.getProducts(_productLists);
for (var item in items) {
print('${item.toString()}');
this._items.add(item);
}
setState(() {
this._items = items;
this._purchases = [];
});
_getPurchases();
}
Future _getPurchases() async {
List<PurchasedItem> items = await FlutterInappPurchase.instance.getAvailablePurchases();
for (var item in items) {
print('${item.toString()}');
this._purchases.add(item);
}
setState(() {
this._items = [];
this._purchases = items;
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: RaisedButton(
onPressed: () {
_requestPurchase(_items[0]);
},
child: Text("Buy Item"),
),
),
);
}
}
当我单击 BuyItem 并调用 requestPurchase() 方法时。我收到以下错误日志并收到类似 "the item you were attempting to purchase could not be found"
的错误W/ActivityThread( 8794): handleWindowVisibility: no activity for token android.os.BinderProxy@572f129 W/ProxyBillingActivity( 8794): Activity finished with resultCode 0 and billing's responseCode: 6 W/BillingHelper( 8794): Couldn't find purchase lists, trying to find single data. W/BillingHelper( 8794): Received a bad purchase data. W/BillingHelper( 8794): Couldn't find single purchase data as well. E/DoobooUtils( 8794): Error Code : 6 I/flutter ( 8794): purchase-error: responseCode: 6, debugMessage: , code: E_UNKNOWN, message: An unknown or unexpected error has occured. Please try again later.
请提出解决方案。
谢谢。
我认为您的应用内商品将处于非活动状态。
默认情况下,当您在播放控制台中添加托管产品时,它会处于非活动状态。因此,只需在您的 google 游戏控制台帐户中访问您的应用内产品并验证它是否有效。
此外,请确保您 developing/testing 应用的 VersionCode 和 VersionName 至少应为 google 游戏开发者 console/play 商店中的版本。
对于 flutter,您可以在 pubspec.yaml 文件中检查版本控制。