检测已购买的产品时出现问题(Inapp iphone sdk)

发布于 2024-11-09 14:54:10 字数 589 浏览 0 评论 0原文

我正在尝试在我的应用程序上添加 Inapp 产品。

  1. 我可以列出我创建的应用内产品。
  2. 我可以显示付款弹出窗口,并且可以毫无问题地购买产品。

但是...当我启动应用程序时,我无法验证该设备是否已经购买了该产品。

我正在使用 MKStore 类,它有一个函数来验证产品是否已经购买:

if([[NSUserDefaults standardUserDefaults] boolForKey:@"Myproduct1"]){
           NSLog(@"Already Purchased");
}

但我总是收到 false。

如果我打开应用程序,然后按下按钮再次购买该产品,我会收到一条提醒,例如“您已经购买了该产品,请按确定下载它。”。

付款正常,但我不知道如何验证它...我想在应用程序启动时禁用已购买的产品上的“付款”按钮。

编辑:

解决了!但是...如果我卸载该应用程序,标准UserDefaults将重新启动,并且我不知道已购买哪些产品...有某种方法可以询问Apple,该产品是否已购买?

I'm trying to add Inapp products on my app.

  1. I can list the inapp products that I created.
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

葵雨 2024-11-16 14:54:10

看来您还没有真正设置用户默认密钥。

当您完成购买后,您需要在用户默认值中设置相应的密钥,如下所示:

- (void)product1WasPurchased
{
    // Remember that product 1 was purchased.
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"Myproduct1"];
    // If you want to be sure that the preferences are saved immediately
    // you need to call:
    [[NSUserDefaults standardUserDefaults] synchronize];

    // Do some other stuff.
    ...
}

只有在您实际设置了 bool 后,您的检查才能成功:

if([[NSUserDefaults standardUserDefaults] boolForKey:@"Myproduct1"]){
    NSLog(@"Already Purchased");
}

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:

- (void)product1WasPurchased
{
    // Remember that product 1 was purchased.
    [[NSUserDefaults standardUserDefaults] setBool:YES forKey:@"Myproduct1"];
    // If you want to be sure that the preferences are saved immediately
    // you need to call:
    [[NSUserDefaults standardUserDefaults] synchronize];

    // Do some other stuff.
    ...
}

Only after you have actually set the bool your check can succeed:

if([[NSUserDefaults standardUserDefaults] boolForKey:@"Myproduct1"]){
    NSLog(@"Already Purchased");
}
帥小哥 2024-11-16 14:54:10

我知道执行此操作的唯一方法是将收据对象发送到您的服务器,并将其存储在数据库中。

这样,您就可以管理购买,至少在逐个设备的基础上进行管理,并且您还可以获得额外的好处,即能够在应用程序代码之外向 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文