UIButton error with SKPayment

72 views Asked by At

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?

2

There are 2 answers

6
Larme On

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.

0
mojo On

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