简体   繁体   English

如何检查用户已经购买了应用程序?

[英]How to check does user already bought app?

I've working code to make or restore purchase. 我正在使用代码进行购买或恢复购买。 I'm able to buy and restore. 我可以购买和恢复。

My idea is to put two buttons on purchase screen: "Buy" and "Restore". 我的想法是在购买屏幕上放置两个按钮:“购买”和“还原”。

I want to eneble/disable those buttons depending on purchase status. 我想根据购买状态启用/禁用这些按钮。

Simply: 只是:

  1. If user not bought yet -> "Buy" enabled and "Restore" disabled 如果用户尚未购买->启用“购买”而禁用“还原”

  2. If user bought alredy -> no purchase screen :) 如果用户购买了alredy->没有购买屏幕:)

  3. If user bought alredy and reinstal app - "Buy" disabled and "Restore" enabled 如果用户购买了可重新安装的应用-禁用“购买”并启用“恢复”

Of course I'm using standardUserDefaults but problem starts whe user reinstal app. 当然,我正在使用standardUserDefaults,但是问题开始于用户重新安装应用程序。 My question is how to get purchase status from appStore (purchased or not yet)? 我的问题是如何从appStore获取购买状态(是否购买)?

You shouldn't do this because Apple requires to always have a restore button or your app will get rejected. 您不应该这样做,因为Apple需要始终有一个还原按钮,否则您的应用将被拒绝。

You also shouldn't disable or hide the buttons depending if something was bought or restored. 您也不应禁用或隐藏按钮,具体取决于是否购买或恢复了某些东西。 If the user presses the buy button on a product he already bought he just gets the product for free again, you are never charged twice. 如果用户在已经购买的产品上按下购买按钮,而又再次免费获得该产品,则您永远不会被收取两次费用。

So I wouldn't even bother trying to do this. 因此,我什至不愿意尝试这样做。 It also properly makes your users experience more confusing. 它还可以使您的用户体验更加混乱。 Better to have a consistent shop experience that doesnt change all the time. 最好拥有始终不变的一致的购物体验。 Also users might be thinking there is a bug in your game because all they see is a button that doesnt work. 此外,用户可能会认为您的游戏中存在错误,因为他们看到的只是一个无法使用的按钮。

Maybe put a little tick or something next to the buy button if you want to indicate to the user that he already bought the item. 如果要向用户指示他已经购买了商品,则可以在“购买”按钮旁边打一个小勾或其他字样。 You must have some sort of bool or other property that gets set, and saved in NSUserDefaults, once a product was bought. 购买产品后,必须设置某种布尔值或其他属性,并将其保存在NSUserDefaults中。 Just use that property to add or remove the tick/indicator. 只需使用该属性即可添加或删除刻度/指标。

If you are wondering how to handle the restore button on first press you should use the restore completed delegate method. 如果您想知道如何在首次按下时处理还原按钮,则应使用还原完成的委托方法。 There you can basically show 2 UIAlertControllers. 在那里,您基本上可以显示2个UIAlertControllers。 1 if nothing restored because nothing was previously bought and 1 that the restore was successful. 1,如果没有恢复,因为以前没有购买任何东西; 1,恢复成功。 Check this question I have answered recently for sample code. 检查这个问题,我最近回答了示例代码。 Restore Purchase : Non-Consumable 恢复购买:非消耗品

"We found that your app offers In-App Purchase/s that can be restored but it does not include a "Restore" feature to allow users to restore the previously purchased In-App Purchase/s. To restore previously purchased In-App Purchase products, it would be appropriate to provide a "Restore" button and initiate the restore process when the "Restore" button is tapped" “我们发现您的应用提供了可以还原的应用内购买,但其中不包含允许用户还原先前购买的应用内购买的“还原”功能。要还原先前购买的应用内购买产品,提供一个“恢复”按钮并在点击“恢复”按钮时启动恢复过程是适当的”

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM