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

问题描述 投票:0回答:2

我正在尝试在我的iOS Xamarin应用程序上实现SetUp Apple Pay按钮。我为它添加了按钮并单击处理程序。然后我使用PKPassLibrary.OpenPaymentSetup()打开钱包。然后,如果用户已成功将卡添加到钱包中,我需要通过将“SetUp ApplePay按钮”更改为“使用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。:我想我可能会观察到不正确的事件。

ios xamarin.ios applepay wallet passkit
2个回答
1
投票

尝试使用以下代码:

     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


0
投票

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

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

另请注意,卡片在将其添加到钱包后15-20秒后激活,因此我正在使用“收听周期”来跟踪卡激活。

当卡片最终被激活时,我将按钮从Setup Apple Pay切换到Apple Pay付款。

© www.soinside.com 2019 - 2024. All rights reserved.