0

Having spent a while trying to work through the tutorial here i am having problems using this in storyboards

If i do as the writer suggests and create an IBACtion for purchase and then link it to my button it doesn't auto link so i have to manually link it.

.h 

-(IBAction) purchase;    ( note no sender )

In the .m file

- (IBAction)purchase:(SKProduct *)product{   ( it has a sender


    SKPayment *payment = [SKPayment paymentWithProduct:product];
    [[SKPaymentQueue defaultQueue] addTransactionObserver:self];
    [[SKPaymentQueue defaultQueue] addPayment:payment];
    NSLog(@"did i make it");

}

If i try to link it i always get an exception error If i create the IBAction in the .h file with a sender it then unhooks the IBAction in the .m file , so i hook it back , and i get an error in

SKPayment *payment = [SKPayment paymentWithProduct:product]; fails with [product identifier error ) which seems to point to it not liking the sender in the IBaction

This is quite difficult to explain so please bare with my attempt but any thoughts or ideas would be most welcome I think this is an excellent tutorial ( one of the best i have seen ) but doesn't seem to work with storyboards Thanks

Community
  • 1
  • 1
clive dancey
  • 143
  • 11

1 Answers1

0

Of course you're having an error when you try to collect an SKProduct as a sender - it's the button that's sending the message, not the product. So, since you won't use the button itself in your logic, you don't really need a sender for this action message.

What you need to do is store the products you receive from the SKProductsRequest. Then, when the buy button is pressed and you receive the action message, determine which product in that stored array corresponds to the one you want to buy. You can do this using the productIdentifier property of SKProduct. Finally, use the appropriate product object to perform the in-app purchase code (which I presume you already have).

Hope this helps!

architectpianist
  • 2,562
  • 1
  • 19
  • 27