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

标签 ios xamarin.ios applepay wallet passkit

我正在尝试在我的 iOS Xamarin 应用程序上实现 SetUp 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.:我想我可能观察到了不正确的事件。

最佳答案

尝试使用以下代码:

     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)静态类 PKPaymentNetwork

关于ios - 处理添加到钱包 Apple Pay 的信用卡,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52150168/

相关文章:

iphone - UIViewController 在新的 ARC 内存管理下没有被释放

iphone - 加载新 View 时播放视频

c# - 如何分配 UIPopoverPresentationControllerDelegate

ios - PKAddPassButton 不适用于 iOS 9

html - 如何在我的 Safari 渲染的 Apple Pay 按钮上获得圆 Angular ?

ios - WatchKit 错误 - 没有通知负载

ios - 如何删除数组swift 4中等于特定值的所有元素?

xcode - sample.xcodeproj 无法打开,因为无法解析项目文件。在 Xcode 界面构建器中打开 Xib 文件时

c# - F#:从 ViewController 中的 Storyboard 访问 UI 元素?

react-native - 将 Google 支付按钮和 Apple 支付按钮集成到 react-native 应用程序中