如何保存或存储 SKPayment 交易?
我想将 SKPayment 交易存储在用户默认设置或设备上,并且我还想稍后将交易数据存储在我的服务器上(尚未完成),以便用户可以在需要时恢复订阅/必要/可能。
我遇到的问题是我尝试保存到用户默认值,但它一直告诉我:
* -[NSUserDefaults setObject:forKey:]:尝试插入非属性值 '{ 交易=“”; '__NSCFDictionary' 类的 }'。
我使用的代码是:
// Save
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setObject:transaction forKey:@"transaction"];
[[NSUserDefaults standardUserDefaults] setObject:dict forKey:@"TransactionReceipt"];
[[NSUserDefaults standardUserDefaults] synchronize];
// Read
NSMutableDictionary *savedDict = [[NSUserDefaults standardUserDefaults] objectForKey:@"MyTransactionReceipt"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(@"Saved stored transaction = %@", savedDict);
我还尝试保存 Transaction 对象本身而不是将其存储在字典中,但这总是给出一个错误,它抱怨
“尝试插入非插入属性值...”
我也尝试使用 NSKeyedArchiver,但我不确定如何编码它来处理 SKPaymentTransaction 的读写。
对此的任何帮助将不胜感激。
谢谢。
I would like to store the SKPayment transaction in the user defaults or on the device, and I also would like to store the transaction data on my server at a later date (not done yet) so that a user can restore a subscription if required/necessary/possible.
The problem I am having is that I try to save to user defaults but it keeps telling me:
* -[NSUserDefaults setObject:forKey:]: Attempt to insert non-property value '{
transaction = ""; }' of class '__NSCFDictionary'.
The code I use is:
// Save
NSMutableDictionary *dict = [NSMutableDictionary dictionary];
[dict setObject:transaction forKey:@"transaction"];
[[NSUserDefaults standardUserDefaults] setObject:dict forKey:@"TransactionReceipt"];
[[NSUserDefaults standardUserDefaults] synchronize];
// Read
NSMutableDictionary *savedDict = [[NSUserDefaults standardUserDefaults] objectForKey:@"MyTransactionReceipt"];
[[NSUserDefaults standardUserDefaults] synchronize];
NSLog(@"Saved stored transaction = %@", savedDict);
I also tried saving the Transaction object itself rather than store it in a dictionary, but this gives always gives an error, where it complains of
"Attempt to insert non-insert property value ..."
I also tried using NSKeyedArchiver, but I wasn't sure how to code it to handle the reading and writing of a SKPaymentTransaction.
Any help on this would be most appreciated.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我通过将交易数据存储在文档目录内的 plist 中解决了该问题。
这对于我的要求来说更容易、更可靠。
对于那些希望做同样事情的人来说,下面是基本代码。
I've resolved the problem by storing the transaction data in a plist inside the documents directory.
This was much easier and much more reliable for my requirements.
Basic code follows for those wishing to do the same.