0

I used this tutorial How do you add an in-app purchase to an iOS application? for SKPayment (verbatim) and I am having trouble linking the purchase buttons on my storyboard to my code.

- (IBAction)purchase:(SKProduct *)product{

I keep getting the following error.

[UIButton productIdentifier]: unrecognized selector sent to instance 0x7ffa08cfbe90

I understand that the tutorial uses a xib file but I am using a storyboard file for my game to link the buttons. Can somebody please tell me how I would link my purchase button in my storyboard to the

- (IBAction)purchase:(SKProduct *)product{

code without getting an unrecognized selector error?

Community
  • 1
  • 1
John
  • 71
  • 8

2 Answers2

0

It's because IBAction expects a sender as its first parameter. And when it's "linked" to a UIButton, that UIButton is the sender (it's automatically sent). That why you get the error, UIButton doesn't know the selector productIdentifier.

If you look carefully to the answer your linked on SO, the methods linked to IB aren't this one. This one is called with [self purchase:someSKProduct], that's why it's not causing the crash on his/her code.

Well, I haven't played with StoreKitFramework, but it seems that this method shouldn't be an IBAction (either here on on the answer, it's confusing, proof: your current issue.). It should be just -(void)purchase:(SKProduct *)product.

Larme
  • 24,190
  • 6
  • 51
  • 81
  • I tried adding `-(void)purchase:(SKProduct *)product` to my code and running the method in my IBAction method, but I'm not sure what to replace the SKProduct object with within the IBAction Method, hence: `[self purchase:(SKProduct *)` – John Jun 10 '15 at 16:02
  • How do you define the product? Which SKProduct is it? Maybe have a look of how the linked answer does – Larme Jun 10 '15 at 16:04
  • Per the code from the tutorial, It's not defined globally it's only defined locally to its method. `- (void)productsRequest:(SKProductsRequest *)request didReceiveResponse:(SKProductsResponse *)response{ SKProduct *validProduct = nil;` – John Jun 10 '15 at 16:09
  • And it's a place filler object here. `- (IBAction)purchase:(SKProduct *)product{ SKPayment *payment = [SKPayment paymentWithProduct:product];` – John Jun 10 '15 at 16:10
  • Do you have any idea of how I can I fix this? @Larme – John Jun 10 '15 at 17:25
  • Then do the same. At the same place if you call it, it should be ok. – Larme Jun 10 '15 at 17:26
0

You should link your purchase button to (IBAction)tapsRemoveAds.

And like what Larme said, you should change:

(IBAction)purchase:(SKProduct *)product

to

(void)purchase:(SKProduct *)product
bofredo
  • 2,348
  • 6
  • 32
  • 51
mojo
  • 5
  • 4