检测已购买的产品时出现问题(Inapp iphone sdk)
我正在尝试在我的应用程序上添加 Inapp 产品。
- 我可以列出我创建的应用内产品。
- 我可以显示付款弹出窗口,并且可以毫无问题地购买产品。
但是...当我启动应用程序时,我无法验证该设备是否已经购买了该产品。
我正在使用 MKStore 类,它有一个函数来验证产品是否已经购买:
if([[NSUserDefaults standardUserDefaults] boolForKey:@"Myproduct1"]){
NSLog(@"Already Purchased");
}
但我总是收到 false。
如果我打开应用程序,然后按下按钮再次购买该产品,我会收到一条提醒,例如“您已经购买了该产品,请按确定下载它。”。
付款正常,但我不知道如何验证它...我想在应用程序启动时禁用已购买的产品上的“付款”按钮。
编辑:
解决了!但是...如果我卸载该应用程序,标准UserDefaults将重新启动,并且我不知道已购买哪些产品...有某种方法可以询问Apple,该产品是否已购买?
I'm trying to add Inapp products on my app.
- I can list the inapp products that I created.
- I can show the payment popup and I can buy the product without problems.
But... I can't verify if this device have already purchased this product, when I launch the app.
I'm using MKStore class, this have a function to verify if the product has been already purchased:
if([[NSUserDefaults standardUserDefaults] boolForKey:@"Myproduct1"]){
NSLog(@"Already Purchased");
}
But I always receive false.
If I open the app, and I press the button to bought again this product , I receive an alert like "You already bought this product, press OK to download it.".
The payment were did okay, but I don't know how verify it... I want to disable the "pay" button on products that has been purchased when the app starts.
EDIT:
solved! But... if I uninstall the app, the standardUserDefaults are restarted and I don't know which products has been purchased... There is some method to ask Apple, if the product is already bought?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来您还没有真正设置用户默认密钥。
当您完成购买后,您需要在用户默认值中设置相应的密钥,如下所示:
只有在您实际设置了 bool 后,您的检查才能成功:
It seems you haven't actually set the user default key.
When you've completed your purchase, you need to set the corresponding key in your user defaults, like this:
Only after you have actually set the bool your check can succeed:
我知道执行此操作的唯一方法是将收据对象发送到您的服务器,并将其存储在数据库中。
这样,您就可以管理购买,至少在逐个设备的基础上进行管理,并且您还可以获得额外的好处,即能够在应用程序代码之外向 Apple 验证您的购买收据,这样就不会轻易被黑客攻击。
缺点是您必须维护服务器和网络服务,并且您的应用程序需要互联网连接来验证其购买。
The only way I know of to do this would be to send the receipt object to your server, and store it in a database.
That way, you can manage purchases, at least on a device-by-device basis, and you get the added benefit of being able to verify your purchase receipt with Apple outside of your app code, where it can't be hacked as easily.
Downside is you have to maintain a server and webservice and your app needs an internet connection to verify its' purchases.