简体   繁体   中英

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. 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

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.

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.

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. Your product identifiers will be imageSet1,imageSet2,imageSet3,imageSet4. And in your application you have 4 template names are 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). When transaction is successfull, you will activate credentials for Spring images.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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