title: Apple Pay detect Wallet has no credit cards
body: <p>I am trying to implement Apple Pay for my app. I have the PKPaymentAuthorizationViewController trying to load up the Apple Pay View. This view controller was being returned as Nil by the constructor if I didn't have any cards already in my wallet. So, I decided to guide the user though the process where they enter their card information. I was able to achieve this using </p>
  
  <pre><code>PKPassLibrary* lib = [[PKPassLibrary alloc] init];
  [lib openPaymentSetup];
  </code></pre>
  
  <p>Here is the part where I have the initialization of the PKPaymentAuthorizationViewController. This returns a valid object on Simulator showing the view. But on a real device without a configured credit card returns nil and runs into an runtime exception. Here is the initialization code: </p>
  
  <pre><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];
  }
  </code></pre>
  
  <p>Here the array is a valid NSArray of PKPaymentSummaryItem which is why is successfully works on simulator. </p>
  
  <p>I need to call the above method of openPaymentSetup, everytime I see a user without the credit card in their wallet. Is there a way to detect that? </p>
  
  <p>Currently I am using </p>
  
  <pre><code>if ( [PKPassLibrary isPassLibraryAvailable] ) {
      PKPassLibrary* lib = [[PKPassLibrary alloc] init];
      if  ([lib passesOfType:PKPassTypePayment].count == 0 ) {
          [lib openPaymentSetup];
     }
  }
  </code></pre>
  
  <p>But this will not work since I am looking at the count of passes in wallet. Which may be like boarding pass for airline, or eventbrite pass, etc. </p>
  
  <p>Looked at :
  <a href="https://stackoverflow.com/questions/26992970/pkpaymentauthorizationviewcontroller-present-as-nil-view-controller">PKPaymentAuthorizationViewController present as nil view controller</a></p>
  
  <p><a href="https://stackoverflow.com/questions/31525861/apple-pay-pkpaymentauthorizationviewcontroller-always-returning-nil-when-loaded">Apple pay PKPaymentauthorizationViewController always returning nil when loaded with Payment request</a></p>
  
  <p><a href="https://developer.apple.com/library/ios/documentation/PassKit/Reference/PKPaymentAuthorizationViewController_Ref/" rel="nofollow noreferrer">https://developer.apple.com/library/ios/documentation/PassKit/Reference/PKPaymentAuthorizationViewController_Ref/</a></p>