user2057209
user2057209

Reputation: 345

In app purchase, ID products

I'm working now on the in-app purchases, but even if i found a tutorial, i have a question. In this tutorial, the buy button is associate with a method like this :

- (void)buyButtonTapped:(id)sender {

UIButton *buyButton = (UIButton *)sender;
SKProduct *product = _products[buyButton.tag];

NSLog(@"Buying %@...", product.productIdentifier);
[[RageIAPHelper sharedInstance] buyProduct:product];

}

But in my app, i don't want to use some table views to show the products; i have already create some UIButtons with customs images.

I try some code like this :

-(void)BuyPackage1
{
SKProduct * productPackage1;
NSString * productID = @"com.razeware.inapprage.drummerrage";   //ID of the tutorial
productPackage1.productIdentifier = productID;
[[RageIAPHelper sharedInstance] buyProduct:productPackage1];
}

But it gives me : "Assignment to readonly property"

And also, is it the good method to create an in-app purchase ? I mean, just taking all this code (from the tutorial) and adapt it to my interface which contain UIButtons and not table view like this ?

Upvotes: 1

Views: 360

Answers (2)

Mohammad Kamar Shad
Mohammad Kamar Shad

Reputation: 6067

See,

"Assignment to readonly property" Indeed, `SKProduct productIdentifier property is readonly, so you can't perform write operation over it.

About your 2 Questions Firstly Think about your requirement what you want to do in your application think over it and then try to write code according to the requirement as you told in your question you don't want to show TableView.And Tutorial just give the understanding of how to code new thing or how to improve existing thing. SO you should see the way inside the tutorial what they have used to making purchases.

I would like to tell you my experience, before using InApp Purchases in my code. I was really felt fear from it,but As read Refrence guide and then start reading tutorial for the same.learned much About InApp Purchase. So i would say to you, Read reference Guide for it,this is about In App Purchases and then try to look into the InApp tutorials like.

Upvotes: 1

sergio
sergio

Reputation: 69027

Indeed, SKProduct productIdentifier property is readonly (source):

productIdentifier

The string that identifies the product to the Apple App Store. (read-only)

 @property(nonatomic, readonly) NSString *productIdentifier

You should inspect your tutorial and understand better how SKProduct objects are returned as part of an SKProductsResponse object. Then you should find a way to associate your buttons to those objects.

And also, is it the good method to create an in-app purchase ? I mean, just taking all this code (from the tutorial) and adapt it to my interface which contain UIButtons and not table view like this ?

I think it is ok, but you should:

  1. understand correctly what the tutorial is doing and why;

  2. adapt correctly the tutorial to your case.

You certainly do not need a table to list your purchasable item.

In any case, my best suggestion is using MKStoreKit, a framework which will allow you to handle all the in-app purchase paraphernalia in 3 lines of code.

Upvotes: 1

Related Questions