JackAppDev / flutter_iap

Flutter iap plugin
MIT License
100 stars 15 forks source link

Issue restoring purchases on iOS #41

Open ItsCalebJones opened 5 years ago

ItsCalebJones commented 5 years ago

I see this in the logs when calling the 'restorePurchases' method, seems I never get a response myself.

flutter: Error found type 'int' is not a subtype of type 'Map<String, dynamic>'

Here's my code - from the best I can tell a response is never returned.

new MergeSemantics(
          child: new ListTile(
            title: new Text('Restore Purchases'),
            subtitle: new Text('Click here to restore in app purchases.'),
            onTap: () async {
              FlutterIap.restorePurchases().then((IAPResponse response) {
                print(response);
                String responseStatus = response.status;
                print("Response: $responseStatus");
                if (response.purchases != null) {
                  List<String> purchasedIds = response.purchases
                      .map((IAPPurchase purchase) => purchase.productIdentifier)
                      .toList();
                  if (purchasedIds.length > 0) {
                    sendUpdates(widget.configuration.copyWith(showAds: false));
                    _prefs.then((SharedPreferences prefs) {
                      return (prefs.setBool('showAds', false));
                    });
                  }
                }
                final snackBar = new SnackBar(
                  content: new Text('Purchase history restored: ' + response.status),
                  duration: new Duration(seconds: 5),
                );
                // Find the Scaffold in the Widget tree and use it to show a SnackBar
                Scaffold.of(context).showSnackBar(snackBar);
              }, onError: (error) {
                // errors caught outside the framework
                print("Error found $error");
              });
            },
          ),
        ),
kmcgill88 commented 5 years ago

This change is causing the error. I'm getting the same thing.

The strange part is the master branch looks different than what code actually got pulled down for me. I see the below after running flutter packages get and inspect the iOS code. screen shot 2018-12-16 at 11 16 27 pm Note it's returning a list of id's,...not a string like everything else. It blows up here trying to parse something other than a JSON string.

I'm guessing something got published and missed the iOS code changes?

ened commented 5 years ago

Could you try this with version 2.0.0-pre1?