问题
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]];
}
回答1:
canMakePayments
- Will return "YES" ( True / 1 ) irrespective of card configuration.
canMakePaymentsUsingNetworks
- Will return "NO" , if card NOT configured or NOT configured properly.
So,should check both... If both should be TRUE then only need to make Button "Apple Pay" visible.
Hope this helps.
回答2:
In swift 3.0 you can check your device support apple pay or not via this funcation is its return true then your device support apple pay. Here are the list of device that support apple pay :
iPhone 5s only if you purchase latest peace
iPhone SE,
iPhone 6 or later,
iPad Pro,
iPad 5th generation,
iPad Air 2,
iPad mini 3 or later,
and Apple Watch.
func applePaySupported() -> Bool {
return PKPaymentAuthorizationViewController.canMakePayments() && PKPaymentAuthorizationViewController.canMakePayments(usingNetworks: [.amex, .visa, .masterCard])
}
来源:https://stackoverflow.com/questions/33785359/how-to-verify-ios-device-supports-apple-pay