【问题标题】:Handle credit card added to the Wallet Apple Pay处理添加到 Wallet Apple Pay 的信用卡
【发布时间】:2018-09-03 12:51:38
【问题描述】:

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

【问题讨论】:

  • 您想知道如何确认用户是否已成功将卡添加到钱包中吗?
  • @LucasZ,你是对的。没错。

标签: ios xamarin.ios applepay wallet passkit


【解决方案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

【讨论】:

  • 问题是这样的:在您的代码分支“用户尚未添加银行卡”我打开钱包应用程序并提示他添加卡。因此,如果用户添加了卡片(以更改 UI),我需要一个回调/事件。
  • 您可以在ViewWillAppear方法中添加判断,当用户添加卡片并返回您的应用时,您可以更新您的UI
  • 因为只能在 Wallet App 中添加卡片,所以两个 App 之间没有回调
  • 是的,我必须跟踪 WiiAppearForeground 应用程序生命周期事件,并确保用户导航到具有 bool 属性的钱包。恐怕当这种方法可能无法正常工作时,可能会有一些边缘用例
【解决方案2】:

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

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

另外请注意,卡在添加到钱包后 15-20 秒后被激活,所以我使用“监听周期”来跟踪卡激活。

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

【讨论】:

  • @LucasZ,是的,但解决方案没有那么漂亮
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-02
  • 2018-10-30
  • 2016-05-14
  • 1970-01-01
  • 2020-04-30
相关资源
最近更新 更多