Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'NSInvalidArgumentException', reason: 'Invalid type in JSON write (__NSDate)' on Cordova 6.0.0 #4

Closed
westonganger opened this issue Mar 16, 2016 · 4 comments

Comments

Projects
None yet
2 participants
@westonganger
Copy link

commented Mar 16, 2016

Im getting the following error when trying to use restorePurchases() on Cordova 6.0.0

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Invalid type in JSON write (__NSDate)'

Before spitting this error the xcode console states something about the purchases being restored but the promise is not yet resolved.

The error is happening in the file CDVJSON_private.m line 25:

NSData* jsonData = [NSJSONSerialization dataWithJSONObject:self
                                                       options:0
                                                         error:&error];

Which ultimately was called from PaymentsPlugin.m line 105:

[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];

From what I read this is about attempting to store a date in a dictionary object. Apparently it must be stored as a string. See http://stackoverflow.com/questions/34995329/pass-nsdate-in-nsdictionary-and-convert-into-nsdata-for-jsondata-fix
or
http://stackoverflow.com/questions/3917250/converting-nsstring-to-nsdate-and-back-again?rq=1

Here is my code to call it:

$rootScope.restoreAdFree = function(){
  inAppPurchase.restorePurchases().then(function(data){
    if(data.productId === 'myapp.adfree'){
      $rootScope.$storage.adfree = true;
    }
  }).catch(function(error){
    console.log(error);
  });
};
@westonganger

This comment has been minimized.

Copy link
Author

commented Mar 16, 2016

I attempted to apply the fix described in the links. You can see the changes here https://github.com/westonganger/cordova-plugin-inapppurchase/commit/f6eb7fc3f45d536441c750b8f5fdc620beb2dc77 The app now builds properly but when calling restorePurchases() the promise runs the error function

@AlexDisler

This comment has been minimized.

Copy link
Owner

commented Mar 17, 2016

Thanks for letting me know, I'll look into it. You can try to comment out the date in the meanwhile, I think it should resolve it. https://github.com/AlexDisler/cordova-plugin-inapppurchase/blob/master/src/ios/PaymentsPlugin.m#L97

@AlexDisler

This comment has been minimized.

Copy link
Owner

commented Mar 17, 2016

Please try the new version 0.2.0 by reinstalling the plugin, should work now.

@AlexDisler

This comment has been minimized.

Copy link
Owner

commented Mar 18, 2016

I'm closing this since the reported problem seems to be resolved but please re-open if you are still having issues.

@AlexDisler AlexDisler closed this Mar 18, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.