处理添加到钱包 Apple Pay 的信用卡

Handle credit card added to the Wallet Apple Pay

我正在尝试在我的 iOS Xamarin 应用程序上实现 SetUp Apple Pay 按钮。我已经为它添加了按钮和点击处理程序。然后我使用 PKPassLibrary.OpenPaymentSetup() 打开钱包。然后,如果用户已成功将卡添加到钱包中,我需要通过将 "SetUp ApplePay button" 更改为 "Pay with Apple Pay" 来处理此事件。但是我找不到工作任何事件处理程序或类似的东西。

我尝试过的:

private PKPassLibrary _library;
private NSObject _walletNotificationSubscription;
private void OnSetuApplePayClicked(object button, EventArgs args)
{
   _library = new PKPassLibrary();
   _library.OpenPaymentSetup();
    _walletNotificationSubscription = PKPassLibrary.Notifications.ObserveDidChange(_library, HandleEventHandler);
}
void HandleEventHandler(object sender, NSNotificationEventArgs e)
      {
         _walletNotificationSubscription.Dispose();

         ViewModel.UpdateApplePay();
         SetButtonVisibility();
      }

但它不起作用。

P.S.: 我想我可能观察到了不正确的事件。

尝试使用以下代码:

     if(PKPaymentAuthorizationViewController.CanMakePayments)
         {
            //the device supports Apple Pay

            //check whether the user can make a payment with a bank card ,such as Amex ,MasterCard,Visa,ChinaUnion and so on
            NSString[] paymentString = { PKPaymentNetwork.Amex, PKPaymentNetwork.ChinaUnionPay, PKPaymentNetwork.MasterCard, PKPaymentNetwork.Visa };

            if(PKPaymentAuthorizationViewController.CanMakePaymentsUsingNetworks(paymentString))
            {
                //user has added bank card ,do something you want
            }
            else
            {
                //user has not added bank card
            }

         }
       else
         {
            //the device doesn't support Apple Pay
         }

还有一些其他的支付方式,你可以去看看

public static class PKPaymentNetwork

似乎没有回调或事件(至少在 Xamarin)。因此,当用户被发送到钱包时,我不得不切换控制器的布尔值 属性,然后,当用户返回应用程序时,我跟踪 "WillEnterForeground" 应用程序事件,我检查是否布尔值 属性 为真(如果为真,则来自电子钱包的用户 returns)。

请注意 "ViewWillAppear" 在这种情况下不起作用,它不是 Android 的 "OnResume" 的类似物。

另请注意,卡在添加到钱包后 15-20 秒后会被激活,因此我使用 "listening cycle" 来跟踪卡激活。

卡最终激活后,我将按钮从“设置 Apple Pay”切换为“使用 Apple Pay 支付”。