Kenneth Transier
Kenneth Transier

Reputation: 65

Stripe iOS library in Swift app resulting in unrecognized selector error

I am attempting to add Apple Pay to a Swift app using Stripe. I am following Stripe's guide. I've created a demo repo to demonstrate the error found below.

I have added the Stripe library, linked the necessary Apple libraries, added an Objective-C bridging header, added a Stripe Publishable Key, enabled the Stripe Enable ApplePay macro, and enabled the ApplePay entitlement.

The issue arises when I attempt to create an actual payment request:

 var request: PKPaymentRequest = Stripe.paymentRequestWithMerchantIdentifier("merchant.fm.kenneth.donate")

My repository explains this in detail.

When I build the app, it results in the following error:

2014-11-09 13:59:33.576 stripeTest2[22128:904179] 
+[Stripe paymentRequestWithMerchantIdentifier:]: 
unrecognized selector sent to class 0x10910a210

2014-11-09 13:59:33.579 stripeTest2[22128:904179] *** 
Terminating app due to uncaught exception 'NSInvalidArgumentException', 
reason: '+[Stripe paymentRequestWithMerchantIdentifier:]: 
unrecognized selector sent to class 0x10910a210'

I assume there must be an issue with the bridge into the Objective-C code in the Stripe library. Any help would be greatly appreciated.

Upvotes: 3

Views: 933

Answers (2)

Dylan Knight
Dylan Knight

Reputation: 151

It also helps if, as I found, you add "Stripe+ApplePay.h" to your bridging header.

Upvotes: 0

jflinter
jflinter

Reputation: 986

This is an interesting case. It seems that __IPHONE_OS_VERSION_MAX_ALLOWED is not defined for pure-Swift apps, so the ApplePay code isn't getting compiled.

As this check isn't strictly necessary (if you #define STRIPE_ENABLE_APPLEPAY but your base SDK is earlier than iOS8, that's basically programmer error), I've taken these checks out of our SDK (I'm an engineer at Stripe). If you go grab the latest version (2.2.2), things should work for you (I cloned your repo and tested that change, and things seem ok).

Thanks for bringing this to our attention!

Jack

Upvotes: 3

Related Questions