简体   繁体   English

iOS应用内购买。 标识购买的产品(非消耗品)。

[英]iOS in-app purchase. Identifying purchased product (non-consumable).

I have a number of image templates for in-app purchase, that stored locally on device. 我有许多用于应用内购买的图像模板,这些模板存储在设备本地。 I have created non-consumable in-app purchase in iTunes Connect. 我在iTunes Connect中创建了非消耗性的应用内购买。 Now I cannot understand, how do I, kinda, assign a particular image to a product identifier? 现在我不明白,该如何为产品标识符分配特定的图像? Because in in-app purchase there is no option to assign it to particular content. 由于在应用内购买中,无法选择将其分配给特定内容。 I am probably missing something here. 我可能在这里错过了一些东西。 From this question that I have to create new product identifier for each image-template I sell. 基于这个问题,我必须为我出售的每个图像模板创建新的产品标识符。 But this made it even more confusing, coz I cannot understand how to link each image to each product identifier. 但这使情况更加混乱,因为我无法理解如何将每个图像链接到每个产品标识符。 Thank you. 谢谢。

In iTunes Connect when you create your in-app purchase, you give to each purchase a Product ID like com.example.purchase1 在创建应用程序内购买时,在iTunes Connect中,您给每个购买一个产品ID,例如com.example.purchase1

After in code you should check which was bought like following: 在代码中之后,您应该检查购买的商品,如下所示:

- (void)paymentQueue:(SKPaymentQueue *)queue updatedTransactions:(NSArray *)transactions   {

    for (SKPaymentTransaction * transaction in transactions) {
        switch (transaction.transactionState)
    {
        case SKPaymentTransactionStatePurchased:
            [self completeTransaction:transaction];
            break;
        case SKPaymentTransactionStateFailed:
            [self failedTransaction:transaction];
            break;
        case SKPaymentTransactionStateRestored:
            [self restoreTransaction:transaction];
        default:
            break;
    }
  };
}

- (void)completeTransaction:(SKPaymentTransaction *)transaction {

    //get and pass productIdentifier of transaction
    [self provideContentForProductIdentifier:transaction.payment.productIdentifier];

    [[SKPaymentQueue defaultQueue] finishTransaction:transaction];
}



- (void)provideContentForProductIdentifier:(NSString *)productIdentifier {

    if ([productIdentifier isEqualToString:@"com.example.purchase1"]) {

      //unlock purchase1

    }

You either have to ship all the images with your app and hard code the mapping of product identifier to image or load the product ids from the app store and use an external web site or server to upload the images for the identifiers. 您要么必须将所有图像随同您的应用一起发货,然后对产品标识符到图像的映射进行硬编码,要么从应用商店中加载产品ID,然后使用外部网站或服务器上传用于标识符的图像。

It is a shame that apple do not let you assign meta data to the products which you can upload with the product identifiers. 苹果不允许您将元数据分配给可以使用产品标识符上传的产品,这真是可惜。 For non consumable items you can now at least host the content on the apple servers. 对于非消耗性物品,您现在至少可以将内容托管在Apple服务器上。

So unfortunately at the moment its hard code it or use an external server you can add images on between app releases. 因此,不幸的是,在目前对其进行硬编码或使用外部服务器的情况下,您可以在应用发布之间添加图像。

Actually You should create nonconsumable in-app for every image-template you want to sell. 实际上,您应该为每个要出售的图像模板创建非消耗性的应用内应用。 Lets think that you have 4 different image-template. 假设您有4个不同的图像模板。 Your product identifiers will be imageSet1,imageSet2,imageSet3,imageSet4. 您的产品标识符将为imageSet1,imageSet2,imageSet3,imageSet4。 And in your application you have 4 template names are Spring,Summer, Autumn, Winter. 在您的应用程序中,您有4个模板名称,分别是Spring,Summer,Autumn,Winter。

When user using your app want to buy Spring, You will send a request to appstore that this user wants to buy imageSet1(it is Spring in your app). 当使用您的应用的用户想要购买Spring时,您将向该应用商店发送该用户想要购买imageSet1(在您的应用中为Spring)的请求。 When transaction is successfull, you will activate credentials for Spring images. 交易成功后,您将激活Spring映像的凭据。

When user change the device or reinstall your app later, When he tries to buy Spring theme again, you have to supply restore option in buy dialog.(it is a must. If you dont supply this option your app will bi rejected.) When he press restore apple will return you that this user bought this before and you will activate Spring theme. 当用户更换设备或稍后重新安装应用程序时,当他再次尝试购买Spring主题时,必须在“购买”对话框中提供还原选项。(这是必须的。如果不提供此选项,则应用程序将被拒绝。)他按restore apple将返回您该用户之前购买过的产品,然后您将激活Spring主题。

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

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