15

I'm starting an Apple Pay integration project and have been able to wire up a transaction on the device, and use Stripe to authorize the payment. The part I'm actually struggling with is the proper way for the device to test whether Apple Pay is supported? Thus, for older Iphone models I would choose to hide the Apple Pay features, even if they have ios8 or ios9 installed.

I can probably check for the device model, and ignore Apply Pay for < Iphone5S. However this gets complicated if I also need to start testing IPad versions, etc.

I was wondering if there is a single method somehow to test if ApplePay is supported?

I found this method online as one idea, however it claimed apple pay was supported in the Iphone5 simulator, which I imagine is not entirely true. I do not have an Iphone5 actual device to test with unfortunately.

- (BOOL) applePaySupported {
    return [PKPaymentAuthorizationViewController canMakePaymentsUsingNetworks:@[PKPaymentNetworkAmex, PKPaymentNetworkVisa, PKPaymentNetworkMasterCard]];
}

EDIT/SOLUTION:

I now use this line and it is verified to work for Iphone5 (not supported) vs Iphone6 (supported); and I presume other devices. I'm not entirely sure it always works in Simulator but ApplePay is a little odd in there anyway and testing is best done on device.

- (BOOL) applePaySupported {
    return [PKPaymentAuthorizationViewController canMakePayments] && [PKPaymentAuthorizationViewController canMakePaymentsUsingNetworks:@[PKPaymentNetworkAmex, PKPaymentNetworkVisa, PKPaymentNetworkMasterCard]];
}
4

2 回答 2

11

canMakePayments- 无论卡配置如何,都会返回“YES”(真/1)。

canMakePaymentsUsingNetworks- 如果卡未配置或未正确配置,将返回“NO”。

所以,应该检查两者......如果两者都应该是 TRUE 那么只需要使按钮“Apple Pay”可见。

希望这可以帮助。

于 2015-11-18T17:04:28.460 回答
3

在 s wift 3.0中,您可以通过此功能检查您的设备是否支持 Apple Pay,如果它返回 true,则您的设备支持 Apple Pay。以下是支持 Apple Pay 的设备列表:

iPhone 5s 仅当您购买最新和平

iPhone SE,

iPhone 6 或更高版本,

iPad 临,

iPad 第 5 代,

iPad 空气 2,

iPad mini 3 或更高版本,

和苹果手表。

func applePaySupported() -> Bool {
            return PKPaymentAuthorizationViewController.canMakePayments() && PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [.amex, .visa, .masterCard])
}
于 2017-12-16T11:55:09.563 回答