本文介绍了iPhone - 应用内购买耗材正确的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建的这个新应用程序将使用消费类应用内购买。

I have this new app I am creating that will use consumable in-app purchases.

我的问题是:这是如何工作的?我的意思是,想象用户购买消费品。因此,在完成销售后,我在应用程序的数据库上设置了一个标志,授权使用该对象。我读到某个地方,我必须为用户提供一个按钮来恢复旧的交易,以防用户出于某种原因丢失他的设备并且必须恢复所有内容。

My question is this: how does that work? I mean, imagine the user buys a consumable stuff. So, after finalizing the sell I set a flag on the app's database authorizing the use of that object. I read somewhere that I have to provide the user with a button to restore old transactions in case of the user for some reason loses his device and has to restore everything.

想象一下,用户已经使用了该购买,之后他恢复了旧的应用内购买。那么会发生什么?用户是否会再次使用相同的资源,这样他可以第二次使用而无需付费?它是如何工作的,我应该如何处理?

Imagine the user has already used that purchase and after that he restores the old in-app purchases. What happens then? Will the user have the same resources again, so he can use a second time without paying? How it works and how should I approach that?

谢谢

推荐答案

我想分享一个有点非正统的解决方案,我发现这个问题具有不需要服务器的巨大优势。如果删除并重新安装应用程序,此方法允许用户恢复其消耗品,但不允许他们将项目移动到新设备(除非他们的所有应用程序数据都被复制)。

I wanted to share a somewhat unorthodox solution I found to this problem that has the HUGE advantage of not requiring a server. This method allows users to restore their consumable items if the app is deleted and reinstalled, but does not allow them to move the items to a new device (unless all their app data is copied over).

删除并重新安装应用程序时,存储在钥匙串中的数据仍然存在。钥匙串用于存储用户名和密码,但您也可以在那里存储有关消耗品购买的信息。我使用了KeychainItemWrapper类,可以在这里找到:

Data stored in the keychain persists when an app is deleted and reinstalled. The keychain is intended for storing usernames and passwords, but you can also store information about consumable purchases in there. I used the KeychainItemWrapper class, available here: https://developer.apple.com/library/content/samplecode/GenericKeychain/Introduction/Intro.html

以下是我存储和检索数量的示例代码用户剩余的付费提示:

Here is some sample code where I store and retrieve the number of paid hints that a user has remaining:

//Storing the consumable hint item count
int hintsLeft = 100;
KeychainItemWrapper *wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"Hints" accessGroup:nil];
NSString *hintsString = [NSString stringWithFormat:@"%i",hintsLeft];
[wrapper setObject:hintsString forKey:(id)kSecValueData];
[wrapper release];

//Retrieving it
KeychainItemWrapper *wrapper = [[KeychainItemWrapper alloc] initWithIdentifier:@"Hints" accessGroup:nil];
NSString *numHints = [wrapper objectForKey:(id)kSecValueData];
[wrapper release];
int retrievedHints = [numHints intValue];

注意:


  • 键(id)kSecValueData不能是任意字符串,有一组可用作键的常量列表。

  • the key (id)kSecValueData can't be an arbitrary string, there is a set list of constants that you can use as the key.

您需要添加安全框架

这篇关于iPhone - 应用内购买耗材正确的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-16 08:40