I am trying to implement Apple Pay for my application. I have a PKPaymentAuthorizationViewController trying to download Apple Pay View. This view manager was returned by the constructor as Nil, if I did not have any cards already in my wallet. So, I decided to guide the user, although the process is when they enter information about their card. I was able to achieve this using
PKPassLibrary* lib = [[PKPassLibrary alloc] init]; [lib openPaymentSetup];
Here is the part where I have PKPaymentAuthorizationViewController initialization. This returns a valid object on the Simulator showing the view. But on a real device without a configured credit card, nil is returned and an exception is thrown at runtime. Here is the initialization code:
if ([PKPaymentAuthorizationViewController canMakePayments]) { // init arr [arr addObject:total]; request.paymentSummaryItems = arr; PKPaymentAuthorizationViewController *paymentPane = [[PKPaymentAuthorizationViewController alloc] initWithPaymentRequest:request]; paymentPane.delegate = self; [self presentViewController:paymentPane animated:TRUE completion:nil]; }
Here the array is a valid NSArray PKPaymentSummaryItem, so it works successfully on the simulator.
I need to call the above openPaymentSetup method, every time I see a user without a credit card in my wallet. Is there any way to detect this?
I am currently using
if ( [PKPassLibrary isPassLibraryAvailable] ) { PKPassLibrary* lib = [[PKPassLibrary alloc] init]; if ([lib passesOfType:PKPassTypePayment].count == 0 ) { [lib openPaymentSetup]; } }
But this will not work, as I look at the number of passes in the wallet. Which can be like a boarding pass for an airline, or an eventbrite pass, etc.
Looked: PKPaymentAuthorizationViewController is present as a nil view controller
Apple pays PKPaymentauthorizationViewController always returns nil on boot using a payment request
https://developer.apple.com/library/ios/documentation/PassKit/Reference/PKPaymentAuthorizationViewController_Ref/